Skip to content

Manas Bhardwaj's Stream Posts

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;