我想在设置网站集之后设置SharingCapability属性。我使用了PnP的文档,您可以在此处找到(External Sharing APIs for SharePoint and OneDrive for Business (Core.ExternalSharing))
当我将属性设置为“ ExternalUserAndGuestSharing”时,什么也没有发生。该网站集仍被禁止与外部共享。
这是我的代码:
public static void SetSharingCapability(string fullWebUrl, ClientContext context)
{
Tenant tenant = new Tenant(context);
SiteProperties siteProp = tenant.GetSitePropertiesByUrl(fullWebUrl, true);
context.Load(siteProp);
context.ExecuteQuery();
siteProp.SharingCapability = SharingCapabilities.ExternalUserAndGuestSharing;
siteProp.Update();
context.ExecuteQuery();
}
您对解决“问题”有何建议?
答案 0 :(得分:1)
很可能在应用设置(SharingCapability
之后的那一刻,操作本身尚未完成,并且尚未反映出更新设置的原因:
siteProp.SharingCapability = SharingCapabilities.ExternalUserAndGuestSharing;
siteProp.Update();
context.ExecuteQuery(); //<- even though the query is submitted to the server there is no guarantee at this moment the update operation is completed
要确保更新操作已完成,您可以考虑以下解决方案:
public static void SetSharingCapability(string fullWebUrl, ClientContext context)
{
Tenant tenant = new Tenant(context);
SiteProperties siteProp = tenant.GetSitePropertiesByUrl(fullWebUrl, true);
siteProp.SharingCapability = SharingCapabilities.Disabled;
siteProp.Update();
context.ExecuteQuery();
siteProp = tenant.GetSitePropertiesByUrl(fullWebUrl, true);
context.Load(siteProp, p => p.Status);
context.ExecuteQuery();
while (siteProp.Status == "Updating")
{
Thread.Sleep(TimeSpan.FromSeconds(1));
siteProp = tenant.GetSitePropertiesByUrl(fullWebUrl, true);
context.Load(siteProp);
context.ExecuteQuery();
}
}