2008-09-14 9 views

답변

5

당신을 위해 일을 얻을 수 있도록해야 코드입니다. 당신이 엄격하게 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 
+1

프로필 [PropertyContants.PictureURL]은 컬렉션을 반환하므로 문자열을 직접 형변환 할 수 없기 때문에 값을 가져와야합니다. –

+1

이것은 MOSS에서만 작동합니다 - WSS 자체는 프로필 관리자 서비스 또는 클래스를 포함하지 않습니다. –

2

아, 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} 
    // 
} 
3

(하지 : 당신은 (... 등, 이미지 URL이 실제로 존재 보장, 프로파일이 실제로 존재 보장) 예외를 피하기 위해 몇 가지 추가 검증을 수행해야 할 수 있습니다 MOSS), 그렇다면 실제로 전역 사용자 프로필은 없지만 각 사이트 모음의 숨겨진 사용자 정보 목록은 있습니다. 즉, Microsoft.Office.Server 네임 스페이스의 모든 항목을 사용할 수 없습니다.

그러나 사용자 사진의 URL을 알고있는 한 프로그램 적으로 사용자 정보 목록을 업데이트 할 수 있습니다. 어떤 종류의 상승 된 권한으로 실행하는 한 다른 SharePoint 목록과 마찬가지로 manipulate this list을 사용할 수 있어야합니다. 이 목록은 사이트 모음의 범위에만 적합하므로 사용자가 실제로 사진 URL을 갖도록이 곳곳에 동일한 업데이트를해야합니다. 플러스 사용자는 다른 사용자가 일종의 권한을 사용자에게 할당 할 때까지는 사용자 정보 목록에 들어 가지 않으므로 도메인의 모든 사용자가 거기에있을 수는 없습니다.

분명히 이것을 처리하는 방법은 사용자 프로필 메커니즘이 MOSS이지만 확실히 옵션 인 경우 MOSS VS WSS에 대한 질문을 업데이트해야합니다.