客户端对象模型,找不到网站用户?

时间:2015-04-20 15:47:25

标签: c# sharepoint client-object-model sharepoint-clientobject

我在运行程序时得到ServerException。这是我的代码:

 ClientContext context = new ClientContext("http://myRUL");
 Principal user = context.Web.SiteUsers.GetByLoginName(@"myRealAccoutLoginIn");
 RoleDefinition readDef = context.Web.RoleDefinitions.GetByName("Approve");//"Approve" is the permission I want to give to the user

 RoleDefinitionBindingCollection roleDefCollection = new RoleDefinitionBindingCollection(context);
            roleDefCollection.Add(readDef);
 RoleAssignment newRoleAssignment = context.Web.RoleAssignments.Add(user, roleDefCollection);

 context.ExecuteQuery(); 

以下是enter image description here详细例外:

我可以向您保证网站上存在SiteUsers,下图中的红色圆圈是我的分享点: enter image description here

1 个答案:

答案 0 :(得分:4)

Web.SiteUsers在SharePoint 2010中不存在,并且不会在SharePoint 2013中推荐。

尝试使用Web.EnsureUser("<username>")documentation)获取校长。

相关问题