Search code examples
sharepointphotowindows-sharepoint-services

Getting user photo from SPUser using WSS Object model


I am trying to retrieve a user on Sharepoint's user photo through the WSS 3.0 object model. I have been browsing the web for solutions, but so far I've been unable to find a way to do it. Is it possible, and if so how?


Solution

  • Here is a code snippet that should help get the job done for you. You may need to do some additional validation to avoid any exceptions (ensuring the profile actually exists, ensuring the image URL actually exists, etc...):

        //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