Sunday, 21 August 2011

Get all site collections in SharePoint Web application


A small code snippet to Get all site collections in SharePoint Web application
SPWebApplication webApplication = SPContext.Current.Site.WebApplication;

using (SPSiteCollection siteCollections = webApplication.Sites)
{

foreach (SPSite siteCollection in siteCollections)
{
Label1.Text += siteCollection.Url + “<BR>”;

siteCollection.Close();
}

}

Note : To run the above code reference the Microsoft.SharePoint.Administration.SPWebApplication assembly in your code.

Ads by Google

No comments:

Post a Comment