Home / Archive by category 'Programming'

| RSS

Programmatically Retrieve Information About Windows Services Using ServiceController

ServiceControl can be used to get information about a Windows Service on a machine.  In this post I will show you how to retrieve information about a service using ServiceControl.
To begin with lets examine the properties for ServiceControl. Through the designer we can set the ServiceName property. This can be set to the name of [...]

[ More ] August 29th, 2008 | No Comments | Posted in Programming |

LINQ Equivalent Of Where IN

Working with LINQ to SQL I came across a need of writing a LINQ query equivalent of  T-SQL “Where IN” clause. This is what T-SQL query looks like.

SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address,
City, Region, PostalCode, Country, Phone, Fax
FROM [...]

[ More ] August 25th, 2008 | 8 Comments | Posted in Programming |

Bulk Copy Data Using SQLBulkCopy Class

SQLBulkCopy class in ADO.NET can be used to do bulk copy operations from a .Net application. There are two ways data can be bulk copied using this class. You can either do a single bulk copy or a multiple bulk copy operation. In this post I will show you how to perform a single bulk [...]

[ More ] August 16th, 2008 | 4 Comments | Posted in Programming |

Find Duplicates Using LINQ

How can we find duplicate occurrences of values in a collection? I will demonstrate this here using a collection of cities. City class looks like this:

public class City
{
public string Name { get; set; }
public string Country { get; set; }
}

Cities collection is initialised with this code:

List<City> cities [...]

[ More ] August 16th, 2008 | 1 Comment | Posted in Programming |

Different Flavors Of LINQ

You may have noticed from my blog posts lately that these days I am spending considerable time working with LINQ. Although I mainly concentrate on LINQ To Objects and LINQ To XML, I often wander around and play with other flavors of LINQ as well. Today, just out of curiosity I wanted to see how [...]

[ More ] August 14th, 2008 | 2 Comments | Posted in Programming |

MSDN Library For Visual Studio And .NET 3.5 SP1

While working, you will always find two things running on my machine. One is without any doubt Visual Studio and second is MSDN Library. Since this morning after installing Visual Studio 2008 SP1 I’ve been trying to get my hands on the latest MSDN Library. Thanks to Iftekhar who pointed me to the latest [...]

[ More ] August 13th, 2008 | No Comments | Posted in Programming |

Tutorial Reading A Text File Using LINQ

Introduction
At times us developers have to deal with delimited text files in our applications. Such files have been around since yonks and I often come across data import/export tasks where delimited files are used. Till now the common way in .NET has been to read each line and then extract data using some sort of [...]

[ More ] August 13th, 2008 | 11 Comments | Posted in Programming |

Exam 70-502 Microsoft .NET Framework 3.5 Windows Presentation Foundation Study Links – Part 2

Back in may I posted Part 1 of this series on my old blog. Looking at the statistics it turned out to be one of the highly visited post. Recently I also had a comment asking me when I was publishing other parts of study links. Continuing the same trend here is the second part [...]

[ More ] August 11th, 2008 | No Comments | Posted in Programming |

Refactoring In Visual Studio 2008

While there is a lot of talk about refactoring tools such as Resharper and Refactor Pro, not much is said about refactoring features available in Visual Studio 2008 straight out of the box. I think Resharper and Refactor Pro are fantastic tools but they cost money and most of the time our refactoring needs are [...]

[ More ] August 9th, 2008 | 6 Comments | Posted in Programming |

Write To Vista Event Log Using C#

Event Log is a central place to log application events. These events can be errors, warnings or just information. Each event log entry in Windows Vista has a level of event, date and time the event occurred, source of event, an event Id and a task category. While event logs such as Application, System, Security [...]

[ More ] August 7th, 2008 | 10 Comments | Posted in Programming |

StyleCop Tutorial

StyleCop is a source analysis tool for C#. It can be used for analysing source code as opposed to compiled assemblies which is the area for FxCop. StyleCop is currently in version 4.2 and can be downloaded here. In this tutorial I will show you how to use StyleCop.
I will create a simple console application [...]

[ More ] August 7th, 2008 | 11 Comments | Posted in Programming |

Dynamic Sort With LINQ

In this post I will show you how to perform dynamic sorting with LINQ. I will work with a simple collection of City class. City class is defined below.

public class City
{
public string Name { get; set; }
public string Country { get; set; }
}

The collection is initialised using [...]

[ More ] August 4th, 2008 | 5 Comments | Posted in Programming |