Archive for February, 2009

Add CSS to a page dynamically

February 26, 2009 Leave a comment

 Sometime, we need to add some CSS to a page dynamically.

We can use the following javascript to  add a CSS to a page. This is helful when we are adding/modifying a page in some portal applications like Joomla or Share-point. where we cannot add the CSS to a page in design time.


function AddCSS(skinPath)
              var styles = “@import url(‘ “+skinPath+” ‘);”;
              var newSS=document.createElement(‘link’);

Categories: CSS Tags: ,

Session Expires when Directory.Delete() is called

February 21, 2009 Leave a comment

In DotNet 2.0 and later if we delete some directory inside the web application root, application gets reset and all sessions are expired.

There are different options to resolve this issue, one of the solution is to disable the monitoring on web root:

using System.Reflection;

PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty(“FileChangesMonitor”, BindingFlags.NonPublic | BindingFlags.Public |  BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField(“_dirMonSubdirs”, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod(“StopMonitoring”, BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });

Categories: ASP.Net, C#

C# Coding Standard

February 9, 2009 Leave a comment

While searching for some document on coding standards, i found following links useful:

Categories: C# Tags:

Share-point search

February 9, 2009 1 comment

A client reported that the search feature is not working on a WSS 3.0 share-point portal. All search queries returned the same following text:

No results matching your search were found.

  1. Check your spelling. Are the words in your query spelled correctly?
  2. Try using synonyms. Maybe what you’re looking for uses slightly different words.
  3. Make your search more general. Try more general terms in place of specific ones.
  4. Try your search in a different scope. Different scopes can have different results.

And an error and a warning kept comming on the server every 5 minutes (after every 5 minutes share-point search service tries to index the share-point sites)

We google the error description but the results did not help – then we google the warning text and were able to find the cause of this problem. Here is the warning that kept on coming every 5 minutes

Event Type:   Warning
Event Source: Windows SharePoint Services 3 Search
Event Category:       Gatherer
Event ID:       2436
Date:            12/26/2007
Time:            3:08:16 AM
User:            N/A
Computer:     AZHAR

The start address <sts3://dws571210/contentdbid={8a1d4489-b9bd-4ee6-8d24-d8305c6b64f4}> cannot be crawled. 

Context: Application ‘Search index file on the search server’, Catalog ‘Search’

          The object was not found.   (0x80041201) 

For more information, see Help and Support Center at

Following post helped us in finding the cause of this:

WSSv3 Search, Small Business Server & DNS

As per described in the article, when we tried accessing the site from with-in the server, we were not able to access it. As we were not able to access the site using I.E. the crawler was also not able to access the site and hence it was not indexed. The error The object was not found.   (0x80041201) indicates that the site is not found by the crawler.

As a solution to this problem, we mapped a sub-domain to the existing URL and we verified that the new URL is accessible from with-in the server. Once this is done the site search feature is back up and running

WSS 2.0 Migration

February 9, 2009 Leave a comment

There are different techniques to migrate WSS 2.0 sites from one server to another. We tried different techniques but most of the techniques had one problem or the other.

After searching on internet and reading supporting documents, we tried the Backup/Restore mechanism using the Share-point administration tool “STSADM.EXE”.

STSADM.EXE is provided with Share-point installations and can be found at the path “… Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\BIN”.

This back-up and restore method moved all the customizations of the portal, all data, users and cross site groups and sub-sites were migrated successfully. Following are some special considerations:

  • If there is any custom web part installed on the source server, make sure to install these on the target server.
  • Once the custom web-parts are configured and the security settings are updated, web-parts will start working.


Backup Procedure






Backup filename. For example, backup.dat.



Web site URL. For example, http://server_name/site.



Overwrite any existing backup file or Web site. By default, the backup operation does not overwrite files. If you do not specify this parameter and a backup file or Web site exists, the operation will stop.


 The filename parameter can take any of the following types of information:



  • A filename, such as backup.dat
  • A path on the local hard disk, such as c:\backups\backup.dat
  • A path on a network share, such as \\share\folder\backup.dat

  Note   Before you run the backup operation, you may want to list all of your sites and identify which sites to back up. To see a list of sites on your server, you can use the enumsites operation. Listing the sites with enumsites can be useful when you are automating backups. You can include enumsites in your batch file, parse the list of sites, and then walk through the list of sites to create the backups. The enumsites operation uses the following syntax:

stsadm.exe -o enumsites -url <url>

Restore Procedure

To restore a site, you use the restore operation with the Stsadm.exe command-line tool. The restore operation takes the same parameters as the backup operation: filename, url, and overwrite.

You have three options for restoring sites from a backup.

4.1 You can restore a site over an existing site

Use this option with caution. When you overwrite an existing site, the existing site is completely overwritten. You cannot merge sites. Any existing site content, and existing site permissions, are destroyed when you overwrite a site.


4.2 You can restore a site to a new site on the same server

This is the recommended option. When you restore a site to a new site on the same server, you can copy the data from the restored site, and paste it back into the original site. Use this method if you are restoring a site to recover data.

Note   In order for the restore operation to work correctly, the included and excluded paths for your virtual server must be configured properly. If you are restoring a site to a new site, be sure to create an included path for the site, if necessary, before restoring the site.

4.3 You can restore a site to a separate server

This option can be applied with a separate installation of Windows Share-Point Services that uses a copy of the original server’s configuration database.

This is a more complicated scenario, but it gives you the ability to set up two versions of the same site, as in the previous option, but with the ability to use the unused Web site deletion feature to remove the site automatically after a specific time period. For more information about automatically deleting unused Web sites, see Managing Unused Web Sites.

 Note  If you are trying to recover a particular list or list item from a site backup, use this method to restore the site, and then copy the list or item from the restored site back to the original site.

To restore a site from a backup file, either to a new site or a separate server, you would use syntax similar to the following:

stsadm.exe -o restore -url http://server_name/site -filename backup.dat

To restore a site from a backup file on a server share, and to overwrite any existing site at the new location, you would use syntax similar to the following:

stsadm.exe -o restore -url http://server_name/site -filename \\share\folder\backup.dat

Important Considerations

While we tried the above mentioned process on local server, the backup was not restored and an error was thrown by the restore command that the WSS version is different on local server.
Following is the exact error text:

Error: Your backup is from a different version of Windows SharePoint Services and cannot be restored to a server running the current version

Both the servers had same version of WSS but the live server had Service Pack 1 installed on it, we had to install the same server pack on local server to make the minor version equal to one on live server.

We downloaded following files from the internet and installed these on the local server, which fixed the restore problem:
1. WSS2003-KB924881-FullFile-ENU.exe
2. WSS2003SP1-kb841876-fullfile-enu.exe


Javascript: Close Main Window

February 9, 2009 Leave a comment

When we call window.close(), it closes the popup windows, that are opened up using the…) method, without any issue. But when we try to call the method on a main window, that was not opened up using the…) method, window is not closed  by default and a confirm box is shown first.

In the method window.close(…) javascript simply checks if the window.opener is Null or not, if it is Null a confirm box is shown. So the trick is to set some value in the window.opener variable, this way javascript will treat this window as a popup window and the window.close will work without any message. You can try the following code yourself to experience this:

 /*This function closes the passed (or the current) window without showing the confirm box even if the window is not opened using the method */

          if (!win) //If no windows is passed – close the current window
                    win = window;

          //This will not show the confirm dialog before closing the window.
          //Javascript will treat this window as a Popup.  

”, ‘_parent’, ); 
          //Only for IE-7, this line is not needed for IE6
          //Now the call to window.close() will not display any warning/confirm dialog on IE6 and IE7