Archive for the ‘.Net’ Category

Validating an Australian drivers license number using Regex

Tuesday, February 2nd, 2010

The following code snippet demonstrates validation of an Australian drivers license using Regex.

(more…)

SQL - Returning table with unknown columns

Sunday, November 29th, 2009

Ever wanted to return a table with unknown set of columns from your SQL stored procedure? Yes, you can. Say thanks to SQL XML.
(more…)

C#: Getting last modified file from a directory

Friday, March 20th, 2009

The following code snippet demonstrates how to get the most recently modified file from a directory.
(more…)

Getting Windows Vista and Windows 7 OS name using C#

Wednesday, February 18th, 2009

With Windows Vista getting popular and Windows 7 fast approaching there will soon be a lot of applications running on these platform. Some of the scenarios need to read the OS name dynamically from code. The commonly used method is to extract the OS name using System.OperatingSystem object. It provides a Platform and version number using which you can deduce the OS name.

(more…)

Using Jar files in .Net

Sunday, February 1st, 2009

Even wondered how to use a Java or Jar file in .Net ?

Well, the answer can be complicated or it can be simple too.
(more…)

ASP.NET MVC Action filters

Wednesday, January 14th, 2009

I love the really cool Action Filter’s in ASP.Net MVC. I use it to keep my code clean and reusable. This post is not about what is an Action Filter but is more about how to use them to have cleaner and reusable components.
(more…)

Calculating width of TextBox dynamically based on Text in C#

Tuesday, December 23rd, 2008

Sometimes we need to expand the TextBox dynamically based on the length of the entered text. TextBox does not have a AutoSize property by which it can adjust it’s size based on the content. On way of calculating the Width for the TextBox is using the Graphics.MeasureString and calculating the Pixel width. This method has it’s Pros and cons.

(more…)

Detecting removable drive types using C#

Thursday, November 20th, 2008

Ever wanted to find out the different drives or just the removable drives on the machine ?? The DriveInfo class is the answer to your prayers.

(more…)

IIS7 Executing Directory

Monday, October 27th, 2008

Generally we get the executing directory path using the HttpContext.Request.PhysicalPath etc. In IIS7 this won’t work. We cannot access the HttpContext.Request object in Global.ascx.
This is the way to do this,

int binPos = HttpRuntime.BinDirectory.LastIndexOf("\\bin");
string executingDirectory = HttpRuntime.BinDirectory.Remove(binPos);

Have fun.

WPF Dispatcher CheckAccess not displaying in intellisense

Thursday, October 16th, 2008

This one really struck me hard. I am doing a threading scenario with some UI feedback marshaled back on the UI thread. And you won’t believe it, I am amazed to find CheckAccess missing from the Dispatcher object. Intellisense wouldn’t just show me CheckAccess(). Rubbing my eyes and again checking, it still seems to have vanished…

(more…)