Recently, we came across a situation in our environment in which we needed to enumerate all profiles in MOSS 2007 and add a few new profile properties. One of the properties that needed to be updated is the picture url. All of our employees pictures are located in a separate database and an image handler has already been created to serve out the images. So, we wanted to leverage this to place user pictures into the directory (and turn off the user's ability to modify them).
This project is a service that will run on my MOSS server a pre-determined intervals. I will eventually add it to SharePoint as a timer job to be done just after the user profile import has completed.
So, here's the code that made it work:
First, we need to get a SPSite. This is done by creating a new instance of SPSite passing the site URL to the constructor. Next, we have to pass the site context to the user profile manager's constructor. Then we can iterate through all profiles and retrieve properties of the profile. Each property is returned as a UserProfilePropertyValueCollection. You can get an individual property by calling Prop.Item("PropertyName"). This will return an array of objects. Since most of the properties I'm working with are strings, there's not much of a need to cast them to other object types. Finally, I query the database with the method GetEmployeeID(FirstName,LastName) (which I have not detailed here) and write the values back into the image property using ImageProp.Item(0)=PictureURL. To write the changes to the profile, I finally call profile.Commit.
Hope this simple example can help some of you make necessary changes to your user profile stores in MOSS 2007.