如何在 SharePoint 2013 中通过其登录名获取用户配置文件的 URL
本文关键字:获取 登录 用户 配置文件 URL SharePoint 2013 | 更新日期: 2023-09-27 17:56:17
得到了这个存储库代码。
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;
}
我想获取喜欢某个列表项的用户集合。集合项如下所示:
public class FollowedPerson
{
public string Name { get; set; }
public string ImageUrl { get; set; }
}
获取他们的名字工作正常,但我不知道如何通过他们的登录名获取他们的头像图像。
liker.User //does not contain any url of user`s image
您可以从用户配置文件中获取此信息。您可以在此处阅读有关如何使用它的信息:在 SharePoint 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()));
}