Forum Discussion
Issue Setting Domains AllowList for Sharing in CSOM API
Hi all
We found an issue trying to set allowed domains for sharing through CSOM. When setting the site property's SharingDomainRestrictionMode to AllowList and setting the SharingAllowedDomainList all queries are executed without error, however when looking at the sharing settings in SharePoint the
"Limit external sharing by domain."
checkbox is checked, but the mode is set to
"Don't allow sharing with users from these blocked domains"
and no domains are in the list. The BlockList SharingDomainRestrictionMode works, and the SharingBlockedDomainList can be set. SharingDomainRestrictionMode None also works, only the AllowList does not work as intended.
Does anyone have any idea what's going on here?
var siteProperties = tenant.GetSitePropertiesByUrl(siteCollectionUrl, false);
ctx.Load(siteProperties, s => s.SharingDomainRestrictionMode, s => s.SharingAllowedDomainList);
ctx.ExecuteQueryRetry();
siteProperties.SharingDomainRestrictionMode = SharingDomainRestrictionModes.AllowList;
siteProperties.SharingAllowedDomainList = domainString;
siteProperties.Update();
ctx.ExecuteQueryRetry();
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();
- Borup-DKCopper Contributor
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();- davidrosmonCopper Contributor
- Borup-DKCopper Contributor
- davidrosmonCopper Contributor
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();