Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable External Domain in SPO
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
You can’t perform that action at this time.