.net

Loading Assemblies from a .Net Application in a 'Sandbox Environment'

I am currently developing an application in where a user will dynamically choose dlls and the application will execute some of the methods in that dll. (if you follow the first link, you will see that I am developing a sort of Robocode game application using the .Net Framework). For example, when the battle starts, the run method from ...

Broken tables in RichTextBox control (word wrap)

We are having problems with the Windows.Forms.RichTextBox control in Visual Studio 2008. We are trying to display text supplied as an RTF file by a 3rd party in a windows forms application (.NET 3.5). In this RTF text file there are tables, which contain text that spans multiple lines. The RTF file displays correctly when opened with e...

Help with a Castle Active Record DeleteAll HQL String

So I basically want to have a static method in my AR class to delete all records on a specified expression. But apparently Castle Active Record doesnt have an overload for IQuery params (at least not the version I am using). This is what I am "effectively" trying to acheive: public static void Delete(string pAppIdentifier) { DeleteA...

InstallPrintQueue: how to create a new port? (.net,c#)

I'm fighting here with System.Printing namespace of .net framework. And what i always saw as a wired thing in all the tools by MS to manage my printservers is they lack Port and Driver managing functionality. So I'm stuck here with a piece of code that works: PrintServer _ps = new PrintServer(PServer, PrintSystemDesiredAccess.Adminis...

Force subclasses of an interface to implement ToString [C#]

Say I have an interface IFoo, and I want all subclasses of IFoo to override Object's ToString method. Is this possible? Simply adding the method signature to IFoo as such doesn't work: interface IFoo { String ToString(); } ...since all the subclasses extend Object and provide an implementation that way, so the compiler doesn't c...

How do I stop the DateTimeOffset scale from causing a ChangeConflictException in linq to Sql?

The following code tries to create a new record and then modify it after it has been committed to the database. The last SubmitChanges() call throws a ChangeConflictException. ItemA itemA = new ItemA(); itemA.Foo = "a"; itemA.Created = DateTimeOffset.Now.UtcDateTime; ItemAs.InsertOnSubmit(itemA); SubmitChanges(); itemA.Foo = "b"; Subm...

ResourceProviderFactory periodic refreshing

I've created a custom resource provider which returns strings from our database to use for whatever. The issue is I haven't found a way to "bust" the cache on these items and reload them from the database. Ideally I'd do this every x minutes or manually when we update the cache and want to reload it. Technically, that's easy. I'm stori...

How can I output a number as a string of bits in C#?

In C#, how can I output a number as binary to the console? For example, if I have a uint with the value of 20, how can I print to the console: 00010100 (which is 20 in binary)? ...

How to intercept a Tab key in edit control

Hi, I need custom behavior for tab keys in RichTextEdit control. Currenty the best I have is this: editBox.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.field_PreviewKeyPress); private void field_PreviewKeyPress(object sender, PreviewKeyDownEventArgs e) { switch (e.KeyCode) ...

Setting property's property directly in C#

Lets consider that I have a public property called AvatarSize like the following, public class Foo { ... public Size AvatarSize { get { return myAvatarSize; } set { myAvatarSize = value; } } ... } Now if a target class wants to set this property, then they need to do it the following way, myFoo.AvatarSize = new Si...

C# issue: How do I manipulate a Textbox on one form from another form?

I'm trying to create my own error window for the project I am working on. When I show my error window I have no way to pass the error message, and user message to the Error window because the "ErrorMessage.Text" cannot be seen in the classes I make. I went into the form designer generated code and tried to make the TextBox static, but t...

Connection pooling in the MySQL .NET Connector

I'm creating a website in asp.net and mysql, I noticed that the performance of connection pooling in the mysql .net connector is horrible to say the least! For example sql server is 10x times faster in connection pooling (the sql server .net provider connecting to sql server), is there anything I could do to speed up connection pooling? ...

Your Favorite LINQ-to-Objects Queries

With LINQ, a lot of programming problems can be solved more easily - and in fewer lines of code. What are some the best real-world LINQ-to-Objects queries that you've written? (Best = simplicity & elegance compared to the C# 2.0 / imperative approach). ...

ASP.NET MVC - Manipulating HTTP Post

When a form is posted back to the server, is it possible to manipulate, change, set the values contained in HTTP Post in the controller action? I would like to remove certain textbox values entered by the user so that these values always have to be re-entered (e.g. password fields). By default Html helpers extract initial values for HTML...

ASP.NET ObjectDataSource - reference static properties for parameter names

I use a lot of ObjectDataSources (ods) in my website projects. Almost all of my ods's use SessionParameters; typing the session parameter name into the SessionField property of the ods is annoying and prone to typos. I have a static SessionParams class where I store all the session parameter names, is it possible to reference the membe...

Managed code library to write/read cabinet (.cab) files

I am looking for a managed code library/API or samples that let me write and read cabinet (.cab) files. There is a CAB SDK here: http://support.microsoft.com/kb/310618 but the DLL that ships with it only supports native code. ...

Tutorials for .NET Remoting

I've been looking around for some decent tutorials on .NET remoting (old style MarshallByRef), and have come across a couple, but nothing that I'm happy with. Does anyone know of any decent tutorials around? ...

How can I extract a specific Image from an Icon file in .NET?

Icon files (*.ico) may contain multiple images at different sizes and of different colour depths. How can I obtain a System.Drawing.Image object from a .ico file? One option is Image.FromFile(...), but for icon files with multiple images there is no way to specify which image size and colour depth to return. Ideally the solution would...

Best way to compute UTC/local datetime conversion in a WCF client/server application

I've got a client/server application, written in WCF / C#3.5. The server is in my local TimeZone, and clients are spreaded accross the world. My current strategy is to use UTC DateTime everywhere on the server and in the database, and to let the clients handle correctly the UTC DateTimes they receive. This means that everytime the cli...

API/Library to replace signtool.exe

The Windows SDK ships with a tool called signtool.exe that lets you sign a file with a certificate. I need to do the same thing but in a background service so I'm on the lookout for a library (preferably managed code, but COM will do) to do the same thing. Any ideas? Found the answer. Here's how to use an X.509 certificate to sign a fil...