Archive for the ‘C#’ Category

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…)

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…)

C# Converting Time between TimeZones in C#

Thursday, October 2nd, 2008

.Net 3.5 has introduced a new TimeZoneInfo class which is an improvement over the existing TimeZone class. The TimeZone class can work on local TimeZone only i.e. converting between UTC and Local time zone only. The new TimeZoneInfo class provide much more richer functionality of working with different other Time zone’s.
(more…)

C# Conditional breakpoints - Debugging a thread

Thursday, April 3rd, 2008

One of the cool feature of VS is the ability to set conditional breakpoints i.e. setting a breakpoints which hit based on a condition. When the condition is True the breakpoint will hit or else it won’t.
(more…)

Find if database, table or stored procedure exists using C#

Saturday, February 23rd, 2008

There is a cool list of MetaData functions present in SQL server. I will be discussing one of them - object_id

Often we need to check if the Database is present and if it not then we need to create a new one. The most common answer to this is, try to connect to the Db and if the connection fails/throws an exception then the database does not exist. Do you think it is correct ?
(more…)