Created
September 15, 2017 15:18
-
-
Save chrisobriensp/be287b3b4d868cb2e80f538bd6877f77 to your computer and use it in GitHub Desktop.
Uses Azure App Insights to track site collection creation in SharePoint Online.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ClientContext adminSiteContext = new ClientContext(TENANT_ADMIN_URL); | |
adminSiteContext.Credentials = new SharePointOnlineCredentials(TENANT_ADMIN_USER, securePwd); | |
Web templateWeb = adminSiteContext.Web; | |
adminSiteContext.Load(templateWeb, w => w.Title, w => w.Url); | |
adminSiteContext.ExecuteQueryRetry(); | |
Console.WriteLine("Auth'd to site: " + templateWeb.Url); | |
// create new site collection.. | |
Tenant tenant = new Tenant(adminSiteContext); | |
if (tenant.SiteExists(NEW_SITE_URL)) | |
{ | |
Console.WriteLine(string.Format("Site already exists at URL - {0}", NEW_SITE_URL)); | |
Console.ReadLine(); | |
} | |
else | |
{ | |
var stopwatch = System.Diagnostics.Stopwatch.StartNew(); | |
// ... perform the timed action ... | |
Console.WriteLine(string.Format("Creating site collection at - {0}", NEW_SITE_URL)); | |
tenant.CreateSiteCollection(NEW_SITE_URL, NEW_SITE_TITLE, ADMIN_EMAIL, "STS#0", 500, 400, 7, 7, 1, 1033); | |
stopwatch.Stop(); | |
var siteCreationMetrics = new Dictionary<string, double> { { "processingTime", stopwatch.Elapsed.TotalMilliseconds } }; | |
var siteCreationProperties = new Dictionary<string, string> { { "siteCollectionUrl", NEW_SITE_URL } }; | |
// Send the event: | |
telemetry.TrackEvent("SiteCollectionCreated", siteCreationProperties, siteCreationMetrics); | |
Console.WriteLine(string.Format("Site collection created...", NEW_SITE_URL)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment