Forum Discussion
Issue Setting Domains AllowList for Sharing in CSOM API
- May 09, 2019
If you want to switch between block and allow mode, you need to set the mode to None, then execute and the set it to whatever your looking to do.
var siteProperties = tenant.GetSitePropertiesByUrl(siteCollectionUrl, false);
ctx.Load(siteProperties, s => s.SharingDomainRestrictionMode, s => s.SharingAllowedDomainList);
ctx.ExecuteQueryRetry();
siteProperties.SharingDomainRestrictionMode = SharingDomainRestrictionModes.None;
siteProperties.Update();
ctx.ExecuteQueryRetry();siteProperties.SharingDomainRestrictionMode = SharingDomainRestrictionModes.AllowList;
siteProperties.SharingAllowedDomainList = domainString;
siteProperties.Update();
ctx.ExecuteQueryRetry();
The code below works for me:
Tenant tenant = new Tenant(context);
var siteProperties = tenant.GetSitePropertiesByUrl(url, true);
context.Load(siteProperties);
context.ExecuteQuery();
siteProperties.SharingDomainRestrictionMode = Microsoft.Online.SharePoint.TenantManagement.SharingDomainRestrictionModes.AllowList;
siteProperties.SharingAllowedDomainList = "google.com";
siteProperties.Update();
context.ExecuteQuery();
- Borup-DKApr 29, 2019Copper Contributor