C# 如何在sharepoint 2013中通过用户的登录名获取用户配置文件的URL?
得到了这个存储库代码C# 如何在sharepoint 2013中通过用户的登录名获取用户配置文件的URL?,c#,sharepoint,C#,Sharepoint,得到了这个存储库代码 public IEnumerable<FollowedPerson> ReadFollowedPersonsById(int id, SPList list) { var item = list.GetItemById(id); if (item == null) { return null; } var likedByCollection = (SPFieldUserValueCollection)ite
public IEnumerable<FollowedPerson> ReadFollowedPersonsById(int id, SPList list)
{
var item = list.GetItemById(id);
if (item == null)
{
return null;
}
var likedByCollection = (SPFieldUserValueCollection)item["LikedBy"];
if (likedByCollection == null)
{
return null;
}
var followers = new Collection<FollowedPerson>();
foreach (var liker in likedByCollection)
{
followers.Add(new FollowedPerson
{
Name = liker.User.Name,
ImageUrl = string.Empty //TODO Urls of users avatars
});
}
return followers;
}
获取他们的名字很好,但我不知道如何通过他们的登录名获取他们的头像
liker.User //does not contain any url of user`s image
您可以从用户配置文件中获取此信息。您可以在此处了解如何使用它:。 有用于检索所有用户配置文件属性的代码段:
// Replace the following placeholder values with the target SharePoint site and
// target user.
const string serverUrl = "http://serverName/";
const string targetUser = "domainName\\userName";
// Connect to the client context.
ClientContext clientContext = new ClientContext(serverUrl);
// Get the PeopleManager object and then get the target user's properties.
PeopleManager peopleManager = new PeopleManager(clientContext);
PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);
// Load the request and run it on the server.
// This example requests only the AccountName and UserProfileProperties
// properties of the personProperties object.
clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
clientContext.ExecuteQuery();
foreach (var property in personProperties.UserProfileProperties)
{
Console.WriteLine(string.Format("{0}: {1}",
property.Key.ToString(), property.Value.ToString()));
}
但是如果我没有用户帐户名呢?SPUser类只给我用户Sid、LoginName和Id@k.makarov,LoginName等于用户帐户名,不是吗?我想它也等于。但实际的登录名和帐户名并不相等。所以我尝试用谷歌搜索这个解决方案——从中使用他的登录名获取用户配置文件图像urlSPUser@k.makarov,我想这可能会有帮助。2013年,您的登录名包含身份验证提供商信息(因为索赔)。您可以使用文章中的代码对其进行转换。
// Replace the following placeholder values with the target SharePoint site and
// target user.
const string serverUrl = "http://serverName/";
const string targetUser = "domainName\\userName";
// Connect to the client context.
ClientContext clientContext = new ClientContext(serverUrl);
// Get the PeopleManager object and then get the target user's properties.
PeopleManager peopleManager = new PeopleManager(clientContext);
PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);
// Load the request and run it on the server.
// This example requests only the AccountName and UserProfileProperties
// properties of the personProperties object.
clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
clientContext.ExecuteQuery();
foreach (var property in personProperties.UserProfileProperties)
{
Console.WriteLine(string.Format("{0}: {1}",
property.Key.ToString(), property.Value.ToString()));
}