![](/img/trans.png)
[英]How to create site collection programmatically in SharePoint 2013 using csom c#?
[英]How to programmatically set a user as the Site Collection Administrator in SharePoint
我正在使用SharePoint 2013網站。 我正在嘗試使用以下代碼將用戶設置為網站集管理員:
public void SetUserSiteCollectionAdmin(string siteUrl, string strUserName, string strEmail, string fullName)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.RootWeb)
{
web.AllowUnsafeUpdates = true;
web.AllUsers.Add(strUserName, strEmail, fullName, null);
SPUser spUser = web.SiteUsers[strUserName];
spUser.IsSiteAdmin = true;
spUser.Update();
web.AllowUnsafeUpdates = false;
}
}
});
}
當我在SharePoint 2013網站中轉到“網站設置”並打開“網站集管理員”列表時,我確實看到該用戶被列為網站集管理員。
一切似乎都很好。 現在當我使用相同的用戶名(剛剛添加此網站集管理員列表)打開本網站時,我收到消息:
抱歉,此網站尚未與您分享。
除了將用戶作為“網站集管理員”之外,我還需要做什么其他任何其他設置?
我懷疑這可能與用戶身份如何存儲在SharePoint內容數據庫中有關。 您是否嘗試檢查現有用戶以准確查看username屬性中存儲的內容?
我博客上的這個頁面可能相關也可能不相關,但它描述了基於表單的用戶如何在SharePoint對象模型中存儲得非常奇怪......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.