Within our SPS 2003 environment we stored employee pictures in a picture library. We then set the users Picture URL profile property to point to their picture in this library. The problem was that as soon as we upgraded the paths to these pictures no longer worked. Our pictures were previously found under the path “http://intranet/HumanResources/EmployeePictures/” but after the upgrade the path changed to http://intranet/Topics/Divisions/HumanResources/EmployeePictures/.

So we needed a way to reset the path for all the users in the profile database to reflect this new path (note that in the end we intend to move the photos to a different location as the Topics and Divisions sites that were created will be dumped). My solution was a fairly simple command, called gl-setpictureurlnewpath, which takes in the path to the new picture library and resets all profile users PictureUrl property to reflect this new path. I assume that all the filenames are not changing and that all the photos are in this single library (if your environment has users with photos in different libraries then you’ll want to modify this code to take in another variable to help you determine which ones to change). The core code that does this is shown below:

 1public int Run(string command, StringDictionary keyValues, out string output)
 2{
 3    ...
 4    UserProfileManager profManager = new UserProfileManager(ServerContext.GetContext(sspname));
 5    foreach (UserProfile profile in profManager)
 6    {
 7        if (SetPicture(profile["PictureURL"], librarypath))
 8            profile.Commit();
 9    }
10    ...
11}
12private static bool SetPicture(UserProfileValueCollection val, string libraryPath)
13{
14    string currentUrl;
15    if (val.Value == null)
16        return false;
17    else
18        currentUrl = val.Value.ToString();
19
20    if (string.IsNullOrEmpty(currentUrl))
21        return false;
22
23    string newUrl = libraryPath.TrimEnd('/') + "/";
24    if (currentUrl.IndexOf('/') < 0)
25        newUrl += currentUrl.Trim();
26    else
27    {
28        string file = currentUrl.Substring(currentUrl.LastIndexOf('/'), currentUrl.Length - currentUrl.LastIndexOf('/'));
29        newUrl += file.Trim('/');
30    }
31    val.Value = newUrl;
32
33    return true;
34}

The syntax of the command I created to do this can be seen below.

C:\>stsadm -help gl-setpictureurlnewpath

stsadm -o gl-setpictureurlnewpath

Fixes the pathing for all user photos or a single user's photo as the result of moving a picture library (assumes file names have not changed).

Parameters:
        -sspname <name of the 2007 SSP>
        -librarypath <path to new photo library (i.e., "http://intranet/HumanResources/Employee%20Pictures/")>
        [-username <NT account name>]

Here’s an example of how to change the picture url path for all users:

stsadm –o gl-setpictureurlnewpath –sspname "SSP1" –librarypath "http://intranet/hr/EmployeePictures"