Created
April 3, 2019 03:46
-
-
Save KanwarSingh/d6db7afd7f7e3798584e2d139752157b to your computer and use it in GitHub Desktop.
Enable External Domain in SPO
This file contains 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
Tenant tenant = new Tenant(_context); | |
SPOSitePropertiesEnumerable prop = null; | |
prop = tenant.GetSiteProperties(0, true); | |
_context.Load(prop); | |
_context.ExecuteQuery(); | |
foreach (SiteProperties sp in prop) | |
{ | |
try | |
{ | |
var site_cxt = new ClientContext(sp.Url); | |
site_cxt.Credentials = sp.Context.Credentials; | |
var web = site_cxt.Web; | |
var site = site_cxt.Site; | |
site_cxt.Load(web, w => w.SiteUsers); | |
site_cxt.Load(site); | |
site_cxt.ExecuteQuery(); | |
ScriptSafeDomainEntityData ssded = new ScriptSafeDomainEntityData(); | |
ssded.DomainName = ("http://External-Domain-to-be-added-to-spo"); | |
site.CustomScriptSafeDomains.Create(ssded); | |
site_cxt.ExecuteQueryRetry(); | |
Console.WriteLine(" **** External-Domain added to the site **** " + " : " + sp.Url + ""); | |
strbldr.AppendLine(" **** External-Domain added to the site **** " + " : " + sp.Url + ""); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("---- Exception --- * *" + sp.Url + " - " + ex.Message); | |
strbldr.AppendLine(" ---- Exception --- * *" + sp.Url + " - " + ex.Message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment