Saturday, 24 September 2011

Programmatically get all the site collections for a particular managed path in SharePoint

In this blog we will be seeing how to get all the site collections for a particular managed path in Sharepoint

using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Administration;
namespace
GetAllSCforManagedPath
{
class Program
{
static void Main(string[] args)
{
using (SPSite currentSite = new SPSite("http://serverName:1111/hr/MP3/"))
{
string relativerURL = currentSite.ServerRelativeUrl.ToString(); string[] split =relativerURL.Split('/'); string managedPath = split[1].ToString(); SPSiteCollection siteColl = currentSite.WebApplication.Sites; foreach (SPSite site in siteColl)
{
if (site.ServerRelativeUrl.Contains(managedPath) == true)
{
Console.WriteLine(site.Url.ToString());
}
}
Console.ReadLine();
}
}
}
}

No comments:

Post a Comment