SharePoint Web Part Project – Post Build Commands

When you are building a web part project, you might want to do the following tasks :

  • Move the .dll to the GAC
  • Do a Application Pool Recycle

The following are the variables that we can use in our scripts.

Name Description
$(TargetPath) The full directory path to the output directory, including the project output filename. Example: D:\MyWorks\HelloWorld\bin\debug\HelloWorld.dll
$(TargetDir) The full directory path to the output directory. Example: D:\MyWorks\HelloWorld\bin\debug\
$(ProjectDir) The full directory path to where the project file exists. Example: D:\MyWorks\HelloWorld\

Moving the DLL to the GAC :

The location of the gacutil.exe utility in VS 2008  is different from the VS2005 environment.

VS2008 : C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin

Command : “%programfiles%\Microsoft SDKs\Windows\v6.0A\bin\GacUtil.exe” /if “$(TargetPath)” /nologo

VS2005 : C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin

Command : “%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe” /if “$(TargetPath)” /nologo

Recycling Application Pool :

IIS 6 :

“%systemroot%\system32\iisapp.vbs” /a “sharepoint – 80” /r

if CSCRIPT is not the default host then

%windir%\system32\cscript.exe  “%systemroot%\system32\iisapp.vbs” /a “sharepoint – 80” /r

IIS 7:

“%systemroot%\system32\inetsrv\APPCMD” recycle apppools “Sharepoint – 80”


How to get to the web part maintenance page when your web part page fails?

Sometimes we get stuck with a webpart that crashes on load. And it won’t take you to the webparts maintenance page but will take you to an error page. The way out is to append your page url with querystring ” ?contents=1 “.

For example :  http://MyPortal/Pages/Default.aspx?contents=1

which will take you to http://MyPortal/_layouts/spcontnt.aspx?&url=%2fPages%2fDefault.aspx which is the default web parts maintenance page.

Editing Newform,Editform and DispForm.aspx pages in Browser

By default, SharePoint does not allow you to edit list forms like Newform.aspx, Editform.aspx, Dispform.aspx in the browser. However you can enable edit for those forms by adding  &ToolPaneView=2 to the querystring.

For example your URL should look something like this :


Installing Visual Studio extensions for WSS (VSeWSS) on a Vista machine

I was trying to install the VSeWSS for Visual Studio 2008 on a Vista machine and was in for a little surprise as it would install only if WSS 3.0 is installed. But I found that there is a little hack. It requires some Registry Key tweaking. The following are the steps.

  • Using Regedit reach the registry hive of [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions]
  • Create a new key under that with value 12.0
  • Under 12.0 Create a new string “SharePoint” with value “Installed”

And there you go…You got your dev environment ready.


Thanks Janne Mattila :

Tips : Querying Active Directory Objects using DirectorySearcher

Querying Active Directory objects using the DirectorySearcher can sometimes be challenging. For instance when you have more than 1000 objects in your directory and your FindAll query might fail to return you all the objects. The reason is by default the FindAll method returns only the first 1000 records.

The workaround here is to set the page size.

DirectorySearcher mySearcher = new DirectorySearcher(entry);

mySearcher.PageSize = 500;

Interesting point here is that you should set the page size that is less than 1000. If you set it more than 1000, it will take the server default settings which is 1000. Even though you set the page size as 500 the entire result set is retrieved. Apparently the search results are sliced up into page size of 500 and the entire result set is returned.

We also had a requirement to filter out the disabled users and the DirectorySearch filters can get really tricky. In this case the filter has to be constructed like this…

mySearcher.Filter = “(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))”;

This filter is going to pick all the “person” objects who are not disabled.

The search filter syntax looks a bit complicated, but basically it filters the search results to only include users – “objectCategory=person” and “objectClass=user” – and excludes disabled user accounts by performing a bitwise AND of the userAccountControl flags and the “account disabled” flag, and negating the results. Ref :

Hello world!

Welcome to . Through this blog I would like to share my experience in the world of programming. Also I might stray into some generic topics that interests me 🙂