At one of my clients I needed to create a flexible CSV import to update the user profiles in SharePoint.
In this blog I’m not going to walk through the entire process. I’m going to demonstrate the basic of accessing the user profile information and updating it.
I developed a console application to accomplish my task.
First we’re going to open a site:
using (SPSite site = new SPSite(“http://localhost”))
{
All the Code below is inside this using statement
}
Next we’re going to get Server Content for the site.
Microsoft.Office.Server.ServerContext Context = ServerContext.GetContext(site);
Next we get a User Profile Manager
Microsoft.Office.Server.UserProfiles.UserProfileManager Mngr = new UserProfileManager(Context);
Now I’m going to retreive a particular user using the user’s account
Microsoft.Office.Server.UserProfiles.UserProfile Profile = Mngr.GetUserProfile(“litwareincbrianb”);
Now that I have a user profile, I can query the information in it, and modify it if I choose:
System.Console.Write(Profile[“Title”].Value.ToString());
Profile[“Title”].Value = “New Title”;
Don’t forget the Commit if you want to modify the data.
Profile.Commit();
That’s it. From here you can fill in the blanks.