cmp*_*rer 1 sharepoint sharepoint-2010
我正在尝试使用EnsureUser让用户返回SharePoint Client OM.我的代码是:
ClientContext clientContext = new ClientContext(siteUrl);
User spUser = clientContext.Web.EnsureUser(user);
Run Code Online (Sandbox Code Playgroud)
其中siteUrl和user都是根据需要设置的字符串.
结果是spUser是User对象的shell,但其所有属性(例如Email,Title等)都未初始化.他们在VS中显示{"属性或字段尚未初始化.尚未请求或请求尚未执行.可能需要明确请求."}
会导致什么?我认为如果用户不在那里,EnsureUser会创建用户.我知道在Server OM中有时你需要使用"AllowUnsafeUpdates",对于Client OM有类似的东西吗?
这已经快一年了,但万一其他人正在寻找相同的答案.获取对用户对象的引用后,您需要在访问用户的属性之前执行以下操作.
clientContext.Load(spUser);
clientContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
或者,如果您只想获得电子邮件和标题以减少工资负担.
clientContext.Load(spUser, u => u.Email, u => u.Title);
clientContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
基本上,它会向SharePoint Web建立请求并询问spUser的属性.调用ExecuteQuery()时将发送请求.
| 归档时间: |
|
| 查看次数: |
5945 次 |
| 最近记录: |