Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Programmatically get all the site collections for a particular managed path in SharePoint
WhatsApp
Vijai Anand Ramalingam
13y
28.6
k
0
0
25
Blog
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();
}
}
}
}
Programmatically get all the site collections for a particular managed path in SharePoint
Up Next
How To Get All Site Collection Administrators From SharePoint Online Site Collections Using PnP PowerShell
Ebook Download
View all
SharePoint Framework (SPFx) A Developers Guide
Read by 11.1k people
Download Now!
Learn
View all
Membership not found