我正在尝试通过WSS3.0对象模型检索Sharepoint的用户照片上的用户。我一直在浏览网页寻找解决方案,但到目前为止我还找不到一种方法。这是可能的吗?如果是的话,是如何实现的?
发布于 2008-09-14 17:06:43
这里有一个代码片段,可以帮助你完成这项工作。您可能需要做一些额外的验证以避免任何异常(确保配置文件实际存在,确保图像URL实际存在,等等):
//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发布于 2008-09-17 04:18:00
如果您严格地谈论WSS 3.0 (而不是MOSS),那么您实际上并没有全局用户配置文件本身,而是每个网站集中都有一个隐藏的用户信息列表。这意味着您不能使用Microsoft.Office.Server名称空间中的任何内容。
但是,只要您知道用户图片的URL,就可以通过编程方式更新用户信息列表。只要您以某种提升的权限运行,就应该能够像处理任何其他SharePoint列表一样执行manipulate this list操作。请记住,这个列表只适用于网站集的范围,所以用户必须在所有地方进行相同的更新才能真正拥有一个照片URL。另外,用户不会进入用户信息列表,直到有人给他们分配了某种权限,所以并不是你的域中的每个用户都会在那里。
处理这个问题的最干净的方法是用户配置文件机制是MOSS,但如果这是一个选项,那么问题真的应该更新为询问关于MOSS与WSS的问题。
发布于 2008-09-14 16:38:24
啊,你必须使用UserProfileManager类。更多信息请点击此处:http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofilemanager.aspx
示例用法:
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}
//
}https://stackoverflow.com/questions/61339
复制相似问题