Wednesday, November 09, 2005

How to find the path of the layouts folder of SPS using IIS interface

It looks as it is very difficult to programmatically find the layouts folder of SPS using IIS object model but i found it very easy and interesting using directoryservices and I am sure you will have the same opinion.

private string FindSPSPath( string spsPath )
{
try
{
string metabasePath="IIS://Localhost/W3SVC";
DirectoryEntry path = new DirectoryEntry(metabasePath);
PropertyCollection properties=path.Properties;
DirectoryEntries entries=path.Children;
foreach(DirectoryEntry entry in entries)
{
if( entry.SchemaClassName=="IIsWebServer" && entry.Properties["ServerComment"][0].ToString().ToLower().Equals(spsPath.ToLower()) )
{
DirectoryEntries vdirs = entry.Children;
foreach(DirectoryEntry vdir in vdirs)
if( vdir.Name== "root")
{
DirectoryEntries childVdirs = vdir.Children;
foreach(DirectoryEntry childVdir in childVdirs)
if(childVdir.Name=="_layouts")
return childVdir.Properties["Path"].Value.ToString();
}
}
}
return null;
}
catch
{
throw;
}
}

Here what I have done is to traverse through the collection of children of the IIS Server i.e. IIsWebService. It contains all the Web Servers and Application Pools indicated by a number n following the path IIS://Localhost/W3SVC/n. The next step is to find the appropriate Web Server you are looking for which can be found through the ServerComment property of the Web Server. Also dont forget to check the type of the child of IIS as it can be application pool and application pools dont have such property. The SchemaClassName of the Web Servers is IIsWebServer.

Now we have found the Web Server of the SPS (SharePoint Portal Server). The next step is to find the layouts virtual directory of SPS. Here is something that is typical to SPS. The SPS conatins 2 virtual directories which are not visible through inetmgr that are root and filters. root is the virtual directory that we are interested in as it contains all the rest virtual directories including _vti_bin, layouts etc. So we have now reached to layouts virtual directory of SPS. The final step is to find its physical path. The Path property of virtual directories contain their physical path. In the similar fashion you can find any property of any virtual directory or can modify them.

No comments: