Programmatically 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();
}
}
}
}



SC.png
Ebook Download
View all
Learn
View all