价值不在预期范围内

时间:2012-03-29 15:16:10

标签: exception sharepoint-2010 sharepoint-2007 sharepoint-api

我正在使用Microsoft.Sharepoint.Client命名空间,我正在尝试提供一个ListItem RoleAssignment基于Web中可用的GROUPS。

ClientContext clientContext = new ClientContext(deptUrl);
Web web = clientContext.Web;

RoleAssignmentCollection collGroup = clientContext.Web.RoleAssignments;
clientContext.Load(collGroup,
groups => groups.Include(
    group => group.Member
    ));

clientContext.ExecuteQuery();

List<RoleAssignment> assignments = new List<RoleAssignment>();

foreach (RoleAssignment oGroup in collGroup)
{
assignments.Add(oGroup);
}

然后我按照标题获取List,然后根据我拥有的Id获取ListItem.List list =

web.Lists.GetByTitle('Some List');     
SecurableObject oListItem = list.GetItemById(itemId);

我在oListItem对象上调用BreakRoleInheritence

oListItem.BreakRoleInheritance(false, false);

然后这段代码设置权限:

var item = assignments.Where(x => x.Member.LoginName == groupName).SingleOrDefault();
oListItem.RoleAssignments.Add(item.Member, item.RoleDefinitionBindings);

最后:

clientContext.Load(list);
clientContext.ExecuteQuery();

当我运行代码时,我得到以下错误:

Microsoft.SharePoint.Client.ServerException was unhandled
  Message="Value does not fall within the expected range."
  Source="Microsoft.SharePoint.Client.Runtime"
  ServerErrorCode=-2147024809
  ServerErrorTypeName="System.ArgumentException"
  ServerStackTrace=""
  StackTrace:
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
       at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
       at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
       at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
       at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
       at DisplayOnCalendarUtility.Program.SetSecurity(Int32 caseType, Int32 itemId) in C:\Projects\DisplayOnCalendarUtility\DisplayOnCalendarUtility\Program.cs:line 131
       at DisplayOnCalendarUtility.Program.Main(String[] args) in C:\Projects\DisplayOnCalendarUtility\DisplayOnCalendarUtility\Program.cs:line 54
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

0 个答案:

没有答案