Click here to Skip to main content
Licence CPOL
First Posted 24 Oct 2005
Views 27,739
Bookmarked 9 times

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

By | 24 Oct 2005 | Article
How you can find the path of the layouts folder of SharePoint Portal Server using the IIS interface.

Introduction

It looks like it is very difficult to programmatically find the layouts folder of SPS using the IIS object model but I found a very easy and interesting method using Directory Services and I am sure you will find it easy too.

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;
    }
}

What I have done is, I 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 do not forget to check the type of child of IIS as it can be an application pool and application pools do not have such a property. The SchemaClassName of the Web Servers is IIsWebServer.

Now we have found the Web Server of SPS (SharePoint Portal Server). The next step is to find the layouts virtual directory of SPS. Here, something typical to SPS comes. The SPS contains two virtual directories which are not visible through inetmgr: root and filters. root is the virtual directory that we are interested in as it contains all the virtual directories including _vti_bin, Layouts, etc. So we have now reached the 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 a similar fashion, you can find any property of any virtual directory or modify them.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

S. Akif Kamal

Web Developer

United Arab Emirates United Arab Emirates

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 25 Oct 2005
Article Copyright 2005 by S. Akif Kamal
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid