TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Get site collections from SharePoint Online
Shantha Kumar T
Dec 29
2015
Code
1.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
//using Microsoft.SharePoint.Client;
//using Microsoft.Online.SharePoint.TenantAdministration;
//string weburl = "https://site-admin.sharepoint.com";
//GetSiteCollections(credentials, weburl);
//This method returns the count of Site Collections available in the tenant
//Also returns thr url of all site collections
private
static
void
GetSiteCollections(SharePointOnlineCredentials credentials,
string
weburl)
{
using
(ClientContext ctx =
new
ClientContext(weburl))
{
ctx.Credentials = credentials;
Tenant tenant =
new
Tenant(ctx);
SPOSitePropertiesEnumerable siteCollections = tenant.GetSiteProperties(0,
true
);
ctx.Load(siteCollections);
ctx.ExecuteQuery();
Console.WriteLine(
"Total Site Collections in tenant: "
+ siteCollections.Count.ToString());
foreach
(SiteProperties site
in
siteCollections)
{
Console.WriteLine(site.Url.ToString());
}
}
Console.WriteLine(
"Press any key to exit..."
);
Console.Read();
}
Tenant
SiteCollections