Quantcast
Channel: C# – Random Technical Thoughts
Browsing all 17 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Run app as a specific user

Running an application as a specific user is common practice, but sometimes it’s helps to debug your application if you can run it as a specific user. This does not change security context which the...

View Article


Image may be NSFW.
Clik here to view.

Clear Controls on screen

Here is a method that will clear all the controls on your screen (as long as it matches one of the controls in the method).  It recursively calls itself until all the controls are clear. Here is an...

View Article


Image may be NSFW.
Clik here to view.

How to convert Timezones

Here is a code sample (in C#) that I found for converting datetime between time zones.  This only works in the 3.5 framework (via System.TimeZoneInfo). DateTime oldTime = new DateTime(2007, 6, 23, 10,...

View Article

Image may be NSFW.
Clik here to view.

How to add a row click event to a gridview

So I ran across the problem of I need a web page to do something if a user clicked a row in a grid. It wasn’t going to work for the user to click a button, the whole row had to be clickable. Adding a...

View Article

Image may be NSFW.
Clik here to view.

Method to strip out special characters from a string.

Special characters can cause all kind of trouble. So here is a method that you pass in a string and all the special characters will be removed.   public static string StripSpecialCharacters(string...

View Article


Image may be NSFW.
Clik here to view.

Ternary operator

The .NET framework has a cool feature called the Ternary Operator.  It’s basically a shortcut for  an if/then/else statement. Here’s the format: condition ? first_expression : second_expression; The...

View Article

Image may be NSFW.
Clik here to view.

Generic Send mail method

Here is a generic send mail method. You just need to pass in a subject and body. In your web.config you need a key for the from (notification_from), To (notification_to) and mail server (mail_server)....

View Article

Image may be NSFW.
Clik here to view.

Generic handle error method

Here is a generic handle error method I put in my catches.  It will send an email with the inner exception unless it’s null then you get the exception message.  The stack trace is included. You should...

View Article


Image may be NSFW.
Clik here to view.

How to switch Entity Framework database connected to

If you have a connection to a database through entity framework and you need to switch it to another database (with the exact same structure) you just need to set the Connection.ConnectionString (as...

View Article


Image may be NSFW.
Clik here to view.

Using C# to interface with SQLite

If you need to interface with SQLite there are a couple of steps. 1) You need to get the .net provider for SQLite from sourceforge.net 2) Then add a reference to System.Data.SQLite to your project. 3)...

View Article

Image may be NSFW.
Clik here to view.

How to add a row click event to a gridview

So I ran across the problem of I need a web page to do something if a user clicked a row in a grid. It wasn’t going to work for the user to click a button, the whole row had to be clickable. Adding a...

View Article

Image may be NSFW.
Clik here to view.

Method to strip out special characters from a string.

Special characters can cause all kind of trouble. So here is a method that you pass in a string and all the special characters will be removed.   public static string StripSpecialCharacters(string...

View Article

Image may be NSFW.
Clik here to view.

Ternary operator

The .NET framework has a cool feature called the Ternary Operator.  It’s basically a shortcut for  an if/then/else statement. Here’s the format: condition ? first_expression : second_expression; The...

View Article


Image may be NSFW.
Clik here to view.

Generic Send mail method

Here is a generic send mail method. You just need to pass in a subject and body. In your web.config you need a key for the from (notification_from), To (notification_to) and mail server (mail_server)....

View Article

Image may be NSFW.
Clik here to view.

Generic handle error method

Here is a generic handle error method I put in my catches.  It will send an email with the inner exception unless it’s null then you get the exception message.  The stack trace is included. You should...

View Article


Image may be NSFW.
Clik here to view.

How to switch Entity Framework database connected to

If you have a connection to a database through entity framework and you need to switch it to another database (with the exact same structure) you just need to set the Connection.ConnectionString (as...

View Article

Image may be NSFW.
Clik here to view.

Using C# to interface with SQLite

If you need to interface with SQLite there are a couple of steps. 1) You need to get the .net provider for SQLite from sourceforge.net 2) Then add a reference to System.Data.SQLite to your project. 3)...

View Article

Browsing all 17 articles
Browse latest View live