WSS 3.0 개체 모델을 통해 Sharepoint의 사용자 사진에서 사용자를 검색하려고합니다. 나는 해결책을 찾기 위해 웹을 탐색했지만, 지금까지는 그것을 할 수있는 방법을 찾을 수 없었다. 가능한가, 그렇다면 어떻게 될까?WSS 개체 모델을 사용하여 SPUser에서 사용자 사진 가져 오기
답변
당신을 위해 일을 얻을 수 있도록해야 코드입니다. 당신이 엄격하게 WSS 3.0에 대해 이야기하는 경우
//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
아, 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}
//
}
(하지 : 당신은 (... 등, 이미지 URL이 실제로 존재 보장, 프로파일이 실제로 존재 보장) 예외를 피하기 위해 몇 가지 추가 검증을 수행해야 할 수 있습니다 MOSS), 그렇다면 실제로 전역 사용자 프로필은 없지만 각 사이트 모음의 숨겨진 사용자 정보 목록은 있습니다. 즉, Microsoft.Office.Server 네임 스페이스의 모든 항목을 사용할 수 없습니다.
그러나 사용자 사진의 URL을 알고있는 한 프로그램 적으로 사용자 정보 목록을 업데이트 할 수 있습니다. 어떤 종류의 상승 된 권한으로 실행하는 한 다른 SharePoint 목록과 마찬가지로 manipulate this list을 사용할 수 있어야합니다. 이 목록은 사이트 모음의 범위에만 적합하므로 사용자가 실제로 사진 URL을 갖도록이 곳곳에 동일한 업데이트를해야합니다. 플러스 사용자는 다른 사용자가 일종의 권한을 사용자에게 할당 할 때까지는 사용자 정보 목록에 들어 가지 않으므로 도메인의 모든 사용자가 거기에있을 수는 없습니다.
분명히 이것을 처리하는 방법은 사용자 프로필 메커니즘이 MOSS이지만 확실히 옵션 인 경우 MOSS VS WSS에 대한 질문을 업데이트해야합니다.
프로필 [PropertyContants.PictureURL]은 컬렉션을 반환하므로 문자열을 직접 형변환 할 수 없기 때문에 값을 가져와야합니다. –
이것은 MOSS에서만 작동합니다 - WSS 자체는 프로필 관리자 서비스 또는 클래스를 포함하지 않습니다. –