Skip to content

Author: Manas Bhardwaj

Programmatically retrieve the trigger definition

I ran into this strange situation where I wanted to get Trigger Definition(the SQL content) of a specific trigger from a database. The following SQL query can used to retrieve the trigger definition programmatically.

DB_NAME() AS DataBaseName,
dbo.SysObjects.Name AS TriggerName,
dbo.sysComments.Text AS SqlContent
dbo.SysObjects INNER JOIN
dbo.sysComments ON
dbo.SysObjects.ID = dbo.sysComments.ID
(dbo.SysObjects.xType = 'TR')
dbo.SysObjects.Name LIKE 'YourTriggerName'

Dynamically adding Style Sheet Reference in ASP.Net

In ASP.Net, many times there are scenarios when you want to add a style sheet (CSS) reference to your page from the code behind. Usually, we can do a line (example below) in the page and we are done.

<LINK REL='StyleSheet' HREF='manas.css' TYPE='text/css'>

To do something like this from codebehind, you can use the snippet below.

public void AddHeaderStyleSheetReference(Page PageObject, string StyleSheetURL)
	if (PobjPage.Header != null)
		HtmlGenericControl StyleSheet = new HtmlGenericControl("Link");
		LobjStyleSheet.Attributes.Add("Rel", "StyleSheet");
		LobjStyleSheet.Attributes.Add("Type", "text/css");
		LobjStyleSheet.Attributes.Add("HRef", PageObject.ResolveClientUrl(StyleSheetURL));

A similar approach can be made to add the JavaScript file references to you page.

public void AddHeaderScriptReference(Page PageObject, string ScriptURL)
	if (PageObject.Header != null)
		HtmlGenericControl IncludeScript = new HtmlGenericControl("Script");
		LobjIncludeScript.Attributes.Add("Type", "JavaScript");
		LobjIncludeScript.Attributes.Add("CharSet", "UTF8");
		LobjIncludeScript.Attributes.Add("Src", PageObject.ResolveClientUrl(ScriptURL));

Branch files recursively in VSS

Did you know that there is no way to branch the files recursively in Microsoft VSS?  Here is a work around: From Visual SourceSafe Explorer, go to View ->Search ->WildCard Search Then search for Wildcard: * (a single asterisk) with Search in current project and all subprojects selected. Then it will give you a list of ALL of your files in that project. Simply highlight them all and click on the Branch button.

Access Active Directory – The .NET Way


Accessing Active Director (AD) is one of the most basic scenarios for an Intranet application. For a new developer though, sometimes it becomes clumsy to get this. But believe me, it is just as simple as hitting a full toss (shows how much I love cricket).

Using the Code

The following code shows how to do it with C#. Remember to include System.DirectoryServices. Here you go:

public static Hashtable SearchLDAP(string userID)
    DirectoryEntry entry = new DirectoryEntry("LDAP://DC=Domain,DC=com");
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.Filter = "(&amp;(objectClass=user)(anr="+ userID +"))";


    Hashtable associateDetailsTable = new Hashtable();
    ResultPropertyValueCollection resultCollection;
    SearchResult searchResult = mySearcher.FindOne();

    associateDetailsTable.Add("AssociateID", userID);
    if(searchResult != null)
    resultCollection = searchResult.Properties["givenname"];
    foreach(object result in resultCollection)
    associateDetailsTable.Add("FirstName", result.ToString());
    resultCollection = searchResult.Properties["sn"];
    foreach(object result in resultCollection)
    associateDetailsTable.Add("LastName", result.ToString());
    resultCollection = searchResult.Properties["mail"];
    foreach(object result in resultCollection)
    associateDetailsTable.Add("Mail", result.ToString());
    resultCollection = searchResult.Properties["description"];
    foreach(object result in resultCollection)
    associateDetailsTable.Add("Designation", result.ToString());
    resultCollection = searchResult.Properties["l"];
    foreach(object result in resultCollection)
    associateDetailsTable.Add("Location", result.ToString());
    return associateDetailsTable;

Get the visitor IP Address

The following snippet shows how to retrieve the IP Address of visitor of your website. Usually, the Request object contains the IP Address in the HTTP_X_FORWARDED_FOR key, but sometimes the ISP provider overrides it to make it null. In that case, you can use REMOTE_ADDR.

//Get the client IP Address
string LstrIPAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(LstrIPAddress))
	LstrIPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

Visual Studio Multi Targeting Support

This time Microsoft is ready to battle with all guns up. In the past posts we have discussed the new features of Microsoft Visual Studio 2008 (aka Orcas). One of the big changes they are coming up with this release of Visual Studio is Multi Targeting Support.So, the first question arises into the mind is ‘What is Multi Targeting Support?’

Till the release of Visual Studio 2005, every release targeted a particular version of .Net. Like VS 2002 was for .Net 1.0, VS 2003 was for .Net 1.1 and VS 2005 for .Net 2.0 and later on supported .Net 3.0. VS 2008 by default targets .NET 3.5-but you can now select which .NET version you wish to target your code for at anytime-while creating the project or even during the development. Obviously, if you’re using a feature that an earlier version of .NET doesn’t support and you try to build using that platform, you will get an error. So what is .NET 3.5 anyway? This version is actually a stack built on the new features from .NET 3.0 and beyond-including things like the ASP.NET Ajax Framework and others (which we will discuss shortly). Full support for the core .NET 3.0 functionality is built in. That is, you can now develop WPF and WF apps in both design and source mode without requiring to install add-ons. A large number of project templates also allow you greater flexibility in choosing how you wish to develop and deploy your application-for instance, when creating a WPF application you can select whether to create a normal WPF application for Windows, an XBAP Browser Application or a Custom WPF Control library.

Download Information for Microsoft Visual Studio 2008

Oh!!! If you have got this page by searching for pirated, warez or whatever weird stuffs than I must say that these surf engine giants still have to go a long way to build a proper one. Well, we are not here to discuss about that. We are here to get the early look on Microsoft Visual Studio 2008.The next version of Visual Studio, Microsoft® Visual Studio® 2008 (formerly known as, Microsoft Visual Studio code name “Orcas”), will provide an industry-leading developer experience for Windows Vista, the 2007 Microsoft Office system, and the Web. In addition, it will continue in the Microsoft tradition of development language innovation.Click here to download the Beta 1 version for MS Visual Studio 2008.

Datagridview with filtering capability


The Microsoft Windows Forms Datagridview provided with the MS Visual Studio 2005 has got a lot new and good features which were missing in the datagrid control provided in the earlier versions of MS .Net. But still, many times the developers or I should say the functional need of the application require the filtering capabilities.

In this article, I am gonna explain the method by which we can add the filtering capabilities in the Datagridview header itself.

To just start with and summarize, it can be entirely customized through an xml file and decided to which of columns, the filtering capability is to be provided.

Unlike most of the filtering grids available, it allows you to apply filter on more than one filter at a time and in that too, you can select multiple values in a column. Thus extending the feature for searching/filtering or we should say minimizing the desired view of data to the bare minimum level.



Using the code

FilterDataGridView is a fully customizable user control. As far as the developer’s point of view is concerned. He will not have to make a single line of code change in his code and yet he can achieve the filtering capability. J

As many of the times, we don’t want to give the filtering capability to all the columns that why FilterDataGridView reads the name of the columns from an xml file which have to be enabled for the filtering.

That means what all one developer has to do is to provide an xml file with the name of the columns to be filtered.

Below, I have mentioned what all steps would need to be taken if you want to replace the old Datagridview with the FilterDataGridView.

  1. Add a reference to the FilteredGridViewControl.dll in your project and also add it to your toolbar.
  2. Drag the FilteredGridView from your toolbar to the window form as you do with any other control.
  3. Add FilterGridView.xml to your application. In the compile property, set the Copy to Output folder option.

This xml should look like this:

<?xml version=”1.0″ encoding=”utf-8″ ?>

You can specify as many columns here which are to be filtered.

And here we go, all is set. Wasn’t that simple?

How it works?

With FilteredGridView, when you right click on a header of a column which is there in the list of Columns to be filtered, it will list all the distinct rows. Now you can select any of the row it your grid will automatically be filtered with that value. FilteredGridView supports applying multiple filters on a single column. That means you can apply as many filters on a column and at the same time you can narrow the data by putting filters on other columns data too.


This version of FilterGridView only works when bound with a Data Source.

Download FilteredGridViewControl Code

Download FilteredGridViewControl