帮助解决创建 SharePoint 列表时出现的错误(可能是由于权限问题)
我在尝试激活 Web 部件时遇到错误。它在一种设置中可以正常激活,但在另一种设置中会失败。两者的管理员。似乎它失败了,因为它无法创建列表。错误是:消息:值不能为空。堆栈跟踪:位于 Microsoft.Sharepoint.SPRoleAssignment..ctor 在 ClientRequestHandler.CreateList(...
private static void CreateLists()
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = site.RootWeb)
{
string listName = LIST_NAME;
bool listExist = ContainList(web, listName);
if (!listExist)
{
AddFieldDelegate _delegate = new AddFieldDelegate(AddAttachmentFields);
SPList list = CreateList(web, listName, _delegate);
RegisterList(web, list, KEY);
}
}
}
});
}
catch (Exception ex)
{
throw new Exception(String.Format("Message: {0} Stack Trace: {1}", ex.Message, ex.StackTrace.ToString()));
}
} private static SPList CreateList(SPWeb web, string listName, AddFieldDelegate _delegate)
{
web.AllowUnsafeUpdates = true;
SPListTemplateType genericList = new SPListTemplateType();
genericList = SPListTemplateType.GenericList;
Guid listGuid = web.Lists.Add(listName, "List", genericList);
SPList list = web.Lists[listGuid];
list.Hidden = true;
SPView view = _delegate(list);
view.Update();
//Remove permissions from the list
list.BreakRoleInheritance(false);
//Make site owners the list administrators
SPPrincipal principal = web.AssociatedOwnerGroup as SPPrincipal;
SPRoleAssignment assignment = new SPRoleAssignment(principal);
assignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Administrator));
list.RoleAssignments.Add(assignment);
//update list changes
list.Update();
return list;
}
I'm getting an error when trying to activate a webpart. It activates fine in one setup , but fails in a different one. Administrator in both. Seems like it fails because it's not able to create the list. The error is: Message: Value cannot be null. Stack Trace: at Microsoft.Sharepoint.SPRoleAssignment..ctor
at ClientRequestHandler.CreateList(...
private static void CreateLists()
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = site.RootWeb)
{
string listName = LIST_NAME;
bool listExist = ContainList(web, listName);
if (!listExist)
{
AddFieldDelegate _delegate = new AddFieldDelegate(AddAttachmentFields);
SPList list = CreateList(web, listName, _delegate);
RegisterList(web, list, KEY);
}
}
}
});
}
catch (Exception ex)
{
throw new Exception(String.Format("Message: {0} Stack Trace: {1}", ex.Message, ex.StackTrace.ToString()));
}
} private static SPList CreateList(SPWeb web, string listName, AddFieldDelegate _delegate)
{
web.AllowUnsafeUpdates = true;
SPListTemplateType genericList = new SPListTemplateType();
genericList = SPListTemplateType.GenericList;
Guid listGuid = web.Lists.Add(listName, "List", genericList);
SPList list = web.Lists[listGuid];
list.Hidden = true;
SPView view = _delegate(list);
view.Update();
//Remove permissions from the list
list.BreakRoleInheritance(false);
//Make site owners the list administrators
SPPrincipal principal = web.AssociatedOwnerGroup as SPPrincipal;
SPRoleAssignment assignment = new SPRoleAssignment(principal);
assignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Administrator));
list.RoleAssignments.Add(assignment);
//update list changes
list.Update();
return list;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保相关网站确实有关联的所有者组(/_layouts/groups.aspx -> 设置 -> 设置组)
Make sure that the web in question actually has an associated owner group (/_layouts/groups.aspx -> Settings -> Set Up Groups)