SOLVED

Issue Setting Domains AllowList for Sharing in CSOM API

Copper Contributor

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?

 

sharing.PNG

 

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();

 

4 Replies

@davidrosmon 

 

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-DK

Thanks for the reply.

Is it in Classic or Modern, where it works for you?

@davidrosmon 

 

It is on a Modern Site

best response confirmed by davidrosmon (Copper Contributor)
Solution

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();

1 best response

Accepted Solutions
best response confirmed by davidrosmon (Copper Contributor)
Solution

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();

View solution in original post