• Enumerate SiteCollections

    by  • December 13, 2011 • Administration, SharePoint, SharePoint-2010 • 0 Comments

    SharePoint is the platform where we can store the set of values as items, files as documents in folder or Library. But how we manage all the data’s, there comes Web sites. The above collection of web sites are managed by Site Collection, which is a placeholder or container for all the web sites.

    Here I am enroll the snippet for enumerating the all the site collections from the web application. This Web Application is nothing but a IIS Site and has some specific properties helps to manage the Collection of Site Collections.

                //Retrieving the webapplication based on Url  
                SPWebApplication webapps = SPWebApplication.Lookup(new Uri(“http://localhost”));
                //Gets all the sites under the WebApplication
                SPSiteCollection sites = webapps.Sites;
                //Iterating the site collection and printing
               foreach (SPSite s in sites)
                {
                    Console.WriteLine(s.Url);

                   //Disposing the SiteCollection object, use to clears the memory obtained for SPSite object 
                    s.Dispose();
                }

    Leave a Reply

    Your email address will not be published. Required fields are marked *