我正在编写一个小型 .NET 概念验证控制台应用程序,用于对 SharePoint 文档库执行一系列操作。我注意到以下方法需要一个“编码的”登录名 - 即包含提供者信息的登录名,例如i:0#.w|DOMAIN\user
.
context.Web.EnsureUser(encodedLoginName);
context.Web.SiteUsers.GetByLoginName(encodedLoginName);
如何可靠地将 DOMAIN\user
等用户名转换为 SharePoint 客户端对象模型 中的这种编码格式?
我读过 couple的 blog posts解决了 SPClaimProviderManager
的这个问题,它在客户端 API 中不可用。
最佳答案
我可以使用 ResolvePrincipal 获取编码后的登录名实用方法:
using SP = Microsoft.SharePoint.Client;
//...
// resolve user principal using regular login name or e-mail:
var userPrincipal = SP.Utilities.Utility.ResolvePrincipal(
context,
context.Web,
"DOMAIN\\user", // normal login name
SP.Utilities.PrincipalType.User,
SP.Utilities.PrincipalSource.All,
context.Web.SiteUsers,
false);
context.ExecuteQuery();
// ensure that the user principal was resolved:
if (userPrincipal.Value == null)
throw new Exception("The specified user principal could not be resolved");
// get a User instance based on the encoded login name from userPrincipal
var user = context.Web.SiteUsers.GetByLoginName(userPrincipal.LoginName);
context.Load(user);
context.ExecuteQuery();
这似乎按预期工作。但是,如果有更好的方法或我应该注意的注意事项,请告诉我。
关于c# - "Encoded"SharePoint 客户端对象模型中的登录名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21401391/