Getting user photo from SPUser using WSS Object model

10,484

Solution 1

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

Solution 2

If you are strictly talking about WSS 3.0 (and not MOSS), then you really don't have global user profiles per se, but a hiddenh User Information List in each site collection. That mean none of the stuff in the Microsoft.Office.Server namespaces is available to you.

However, you can update the User Information List programatically as long as you know the URL to a user's picture. As long as you're running with some kind of elevated privileges, you should be able to manipulate this list just like you can with any other SharePoint list. Keep in mind that this list is only good for the scope of a site collection, so users would have to make this same update all over the place to actually have a photo URL. Plus users don't get into the User Information List until someone assigns some kind of permission to them, so not every user in your domain will be in there.

The clean way to handle this is definitely the User Profile mechanism is MOSS, but if that's an option the question should really be updated to ask about MOSS vs WSS.

Share:
10,484

Related videos on Youtube

Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    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?

  • Admin
    Admin almost 16 years
    profile[PropertyContants.PictureURL] returns a collection so you will need to get the value from that since you can't cast it directly to a string.
  • Matt Clark
    Matt Clark over 14 years
    This will only work for MOSS - WSS on its own does not contain the profile manager service or class.