• Insights

Importing Employee Photos into MOSS 2007 MySites

Kraft Kennedy

2 min read

All Insights

Most of the information in an employee’s MySite profile comes from the Active Directory profile import, which is set up in the SharePoint Shared Service Provider.  However, this can be tricky with employee photos since links to photos are not normally stored in Active Directory.  An easy way around this if you don’t want to store the links in Active Directory, is to simply create a picture library in SharePoint and upload all of the employee photos to the picture library with a standard name, such as username.jpg.  Then you can write a script to update each MySite profile and associate the photo with the person.

The code below is VB.Net code to interact with the SharePoint profile database by using the userprofilemanager class.  This will update one profile, so it would need to be put in a loop to update all of the employee profiles.

'Objects for profile database

dim strUrl as string = <site collection url>

dim site as Microsoft.SharePoint.SPSite = new SPSite(strUrl)

dim sc as Microsoft.Office.Server.ServerContext = Microsoft.Office.Server.ServerContext.GetContext(site)

dim upm as UserProfileManager = new UserProfileManager(sc)
dim sAccount as string = "domainusername"
 
Dim u As UserProfile = upm.GetUserProfile(sAccount)        
 
if u.ProfileManager.Properties.GetPropertyByName("PictureURL") is nothing then
 
 'error code
 
else
 
 u("PictureURL").Value = '<put the url plus username.jpg here>
 
 u.Commit
 
end if

Remember to also include the following assembly and namespace...
<%@ Assembly Name="Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
 
<%@ Import Namespace="Microsoft.Office.Server.UserProfiles" %>


If you import additional fields into the profile store, it may be necessary to also run a complete profile import and an incremental search index process to make sure that everything is up to date.  Future profile imports won't overwrite the PictureURL property, so all employee photos should be permanent.  The only drawback is that you will have to run the script for new users or manually enter their picture URL.