Sunday, January 15, 2012

How to get user profile image - sharepoint 2010

There are many way to get user profile image.Here is a one of these methods.



private String getUserImage(String uname){
   SPUserToken userToken = SPContext.Current.Site.SystemAccount.UserToken;
   using (SPSite site = new SPSite("http://someurl.com", userToken)){
                try
                {
                    SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                    Microsoft.Office.Server.UserProfiles.UserProfileManager upm = new             Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);
                    Microsoft.Office.Server.UserProfiles.UserProfile u = upm.GetUserProfile(uname.Trim().ToString());
                    String ur = u.GetProfileValueCollection("PictureURL").ToString();
                    return ur;
                }
                catch (Exception) {
                    return "";
                }
                
            }
        }


No comments:

Post a Comment