.net

Change user for running windows forms program

I wrote a simple Windows Forms program in C#. I want to be able to input a windows user name and password and when I click a login button to run code run as the user I've entered as input. ...

Troubleshooting a NullReference exception in a service

I have a windows service that runs various system monitoring operations. However, when running SNMP related checks, I always get a NullReference exception. The code runs fine when run through the user interface (under my username and password), but always errors running as the service. I've tried running the service as different user ...

Winforms c# - Set focus to first child control of tab page.

Say I have a Textbox nested within a TabControl. When the form loads I would like to focus on that textbox (by default the focus is set to the tabControl). Simply calling textbox1.focus() in the Load event of the form does not appear to work. I have been able to focus it by doing the following: private void frmMainLoad(object se...

How to save persistent objects databound to a DataLayoutControl (DevExpress tools) ?

I have a small form displaying the DataLayoutControl component. If I use a GridControl the objects get saved. If I use the DataLayoutControl (which shows them individually) they do not get saved after they are changed. The underlying object is changed after the user interface edits, but doesn't get saved. How can I enable this ? PS:...

Unhandled exceptions filter in a windows service

I am creating a windows service and want to know best practices for this. In all my windows Program I have a form that asks the user if he wants to report the error and if he answers yes I created a case in FogBugz. What should I do in a windows service. ...

Adding extra information to a custom exception

I've created a custom exception for a very specific problem that can go wrong. I receive data from another system, and I raise the exception if it bombs while trying to parse that data. In my custom exception, I added a field called "ResponseData", so I can track exactly what my code couldn't handle. In custom exceptions such as this on...

Why/when should you use nested classes in .net? Or shouldn't you?

In Kathleen Dollard's recent blog post, she presents an interesting reason to use nested classes in .net. However, she also mentions that FxCop doesn't like nested classes. I'm assuming that the people writing FxCop rules aren't stupid, so there must be reasoning behind that position, but I haven't been able to find it. ...

Multi-Threaded splash screen in c#?

I know this question is all over the net, but I can't quite find what I am looking for and quite frankly this community seems more sophisticated than most I have seen. I want a splash screen to show while the application is loading. I have a form with a system tray control tied to it. I want the splash screen to display while this for...

c# Using WPF and .net 3.5, how can i register a global hot key to say CTRL+SHIFT+(LETTER)

Im building an app in c# using WPF and i need it to bind to some keys. Ive found some links but not work well with my setup. Anyone done this before? also if i could bind to the windows key would be great. ...

Programmatically retrieve database table creation script in .NET

I need to be able to retrieve a CREATE TABLE script to recreate a specific table in a SQL Server (2000) database, programmatically (I'm using C#). Obviously you can do this with Enterprise Manager but I would like to automate it. I've been playing around with SQLDMO which offers a Backup command, but I'm not sure if this will give a SQ...

What's the best .NET library for OpenID and ASP.NET MVC?

I'm looking at using OpenID for my authentication scheme and wanted to know what the best .NET library is to use for MVC specific applications? thx ...

How do I create a MessageBox in C# ?

I have just installed C# for the first time, and at first glance it appears to be very similar to VB6. I decided to start off by trying to make a 'Hello, World!' UI Edition. I started in the Form Designer and made a button named "Click Me!" proceeded to double-click it and typed in MessageBox("Hello, World!"); I received the followin...

How can I use a key blob generated from Win32 CryptoAPI in my .NET application?

I have an existing application that is written in C++ for Windows. This application uses the Win32 CryptoAPI to generate a TripleDES session key for encrypting/decrypting data. We're using the exponent of one trick to export the session key out as a blob, which allows the blob to be stored somewhere in a decrypted format. The question i...

Populating a list of integers in .NET

I need a list of integers from 1 to x where x is set by the user. I could build it with a for loop eg assuming x is an integer set previously: List<int> iList = new List<int>(); for (int i = 1; i <= x; i++) { iList.Add(i); } This seems dumb, surely there's a more elegant way to do this, something like the PHP range method ...

Reading default application settings in C#

I have a number of application settings (in user scope) for my custom grid control. Most of them are color settings. I have a form where the user can customize these colors with a button for reverting to default color settings. By default value I mean what I set in Settings.settings at design time. Is there a way to read the default sett...

Deploy MySQL Server + DB with .Net application.

HI All, We have a .Net 2.0 application which has a MySQL backend. We want to be able to deploy MySQl and the DB when we install the application and im trying to find the best solution. The current setup is to copy the required files to a folder on the local machine and then perform a "NET START" commands to install and start the mysql ...

How do you manage your app when the database goes offline?

Take a .Net Winforms App.. mix in a flakey wireless network connection, stir with a few users who like to simply pull the blue plug out occasionally and for good measure, add a Systems Admin that decides to reboot the SQL server box without warning now and again just to keep everyone on their toes. What are the suggestions and strategie...

How to make a WCF service STA (single-threaded)

I have a WCF service which includes UI components, which forces me to be in STA mode. How do I set the service behaviour to STA-mode? ...

VB.NET FormatNumber equivalent in C#?

Is there a C# equivalent for the VB.NET FormatNumber function? I.e.: JSArrayString += "^" + (String)FormatNumber(inv.RRP * oCountry.ExchangeRate, 2); ...

Controlling which Network Card TCP/IP message are sent on

The system I'm currently working on consists of a controller PC running XP with .Net 2 connected to a set of embedded systems. All these components communicate with each other over an ethernet network. I'm currently using TcpClient.Connect on the XP computer to open a connection to the embedded systems to send TCP/IP messages. I now ha...