![](/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.