Sharepoint 使用WSS对象模型从SPUser获取用户照片

Sharepoint 使用WSS对象模型从SPUser获取用户照片,sharepoint,photo,wss,Sharepoint,Photo,Wss,我正在尝试通过WSS 3.0对象模型检索Sharepoint用户照片上的用户。我一直在浏览网页寻找解决方案,但到目前为止,我还没有找到一种方法。有可能吗?如果有,如何实现?啊,您必须使用UserProfileManager类。 更多信息请点击此处: 示例用法: public override void ItemAdded(SPItemEventProperties properties) { // Get list item on which the event occurred.

我正在尝试通过WSS 3.0对象模型检索Sharepoint用户照片上的用户。我一直在浏览网页寻找解决方案,但到目前为止,我还没有找到一种方法。有可能吗?如果有,如何实现?

啊,您必须使用UserProfileManager类。 更多信息请点击此处:

示例用法:

public override void ItemAdded(SPItemEventProperties properties)
{
    // Get list item on which the event occurred.
    SPListItem item = properties.ListItem;

    // Set the Author Image field to the user's PictureURL if it exists.
    using (SPWeb web = properties.OpenWeb())
    {
        // Author: {C32DB804-FF2D-4656-A38A-B0394BA5C931}
        SPFieldUserValue authorValue = new SPFieldUserValue(properties.OpenWeb(), item[new Guid("{C32DB804-FF2D-4656-A38A-B0394BA5C931}")].ToString());

        UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(web.Site));
        UserProfile profile = profileManager.GetUserProfile(authorValue.LookupId);
        UserProfileValueCollection values = profile[PropertyConstants.PictureUrl];

        if (values.Count > 0)
        {
            // Author Image: {37A5CA4C-7621-44d7-BF3B-583F742CE52F}
            SPFieldUrlValue urlValue = new SPFieldUrlValue(values.Value.ToString());
            item[new Guid("{37A5CA4C-7621-44d7-BF3B-583F742CE52F}")] = urlValue.Url;
        }
    }

    item.Update();

    // News Text: {7F55A8F0-4555-46BC-B24C-222240B862AF}
    //

    // Author Image: {37A5CA4C-7621-44d7-BF3B-583F742CE52F}
    // 

    // Publish Date: {45E84B8B-E161-46C6-AD51-27A42E4992B5}
    //
}

下面是一段代码片段,可以帮助您完成这项工作。您可能需要执行一些额外的验证以避免任何异常(确保配置文件实际存在,确保图像URL实际存在,等等):


如果您严格地说是WSS3.0(而不是MOSS),那么您实际上没有全局用户配置文件本身,而是在每个网站集中有一个隐藏的用户信息列表。这意味着Microsoft.Office.Server命名空间中的任何内容都不可用

但是,只要知道用户图片的URL,就可以通过编程方式更新用户信息列表。只要您以某种提升的权限运行,您就应该能够像处理任何其他SharePoint列表一样运行。请记住,此列表仅适用于网站集的范围,因此用户必须在各地进行相同的更新,才能真正拥有照片URL。另外,除非有人向用户分配某种权限,否则用户不会进入用户信息列表,因此并非您域中的所有用户都会在其中


处理这一问题的干净方法肯定是用户配置文件机制是MOSS,但如果这是一个选项,那么问题应该真正更新为询问MOSS与WSS。

Profile[PropertyContants.PictureURL]返回一个集合,因此您需要从中获取值,因为您无法将其直接强制转换为字符串。这仅适用于MOSS-WSS本身不包含概要文件管理器服务或类。
    //get current profile manager
    UserProfileManager objUserProfileManager = new UserProfileManager(PortalContext.Current);
    //get current users profile
    UserProfile profile = objUserProfileManager.GetUserProfile(true);
    //get user image URL
    string imageUrl = (string)profile[PropertyConstants.PictureUrl];

    //do something here with imageUrl