【问题标题】:Client Object Model, cannot find site user?客户端对象模型,找不到站点用户?
【发布时间】:2015-04-20 15:47:25
【问题描述】:

我在运行程序时收到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(); 

这里是详细异常:

我可以向您保证 SiteUsers 存在于网站上,下图中的红色圆圈是我的共享点帐户:

【问题讨论】:

  • 这个错误出现在哪一行?

标签: c# sharepoint sharepoint-clientobject


【解决方案1】:

Web.SiteUsers 在 SharePoint 2010 中不存在,也不推荐在 SharePoint 2013 中。

尝试使用Web.EnsureUser("<username>") (documentation) 获取委托人。

【讨论】:

  • 成功了,我接受了你的回答。另一个问题,是否可以仅授予某些用户对某些库和文件夹的权限?
  • 有可能。您可以为库、文件夹和列表项/文档中的用户和角色分配独占权限。
  • 好的。不如用Client Object Model写个程序来做呢?
  • 只需更改 context.Web.RoleAssignments.Add 到 context.Web.Lists[
  • 我问了一个新问题,请看一下并提供答案,以便我接受答案并给您声誉。 stackoverflow.com/questions/29754692/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-04
  • 2018-04-14
  • 1970-01-01
  • 2020-12-18
  • 1970-01-01
相关资源
最近更新 更多