Programmatically running a User Profile Import

The User Profile Database in SharePoint is a great centralised location for storing all the information about the users of your SharePoint Portal. This can be anything from their phone number, to their photo through to information about them for their CV. I find it a very useful part of SharePoint, and leverages a lot of features in SharePoint which can be used for social and business networking via SharePoint.

In order to get information into the User Profile Database, a nightly job can be setup which imports user information out of Active Directory – which is where most of this information should reside anyway.

In the current project I am working on, we importing information from various applications into Active Directory (ie from Human Resource Applications) where it is initially added, then after this is imported into Active Directory, we are then using the built in import tool in SharePoint to populate this information into the SharePoint User Profile database so that this information can be used for user searches, organizational hierarchy and on the My Site pages.

However, as these imports are happening using a BizTalk orchestration, we wanted to manually kick off the import in the code ourselves. Bring on the UserProfileConfigManager class. This class makes doing these imports an absolute cinch. Simply create a new instance in the current context, then you can easily kick off an import! If only everything was this easy!!

UserProfileConfigManager upcm = new UserProfileConfigManager(serverContext);
if(!upcm.IsImportInProgress)
    upcm.StartImport(true);
This entry was posted in SharePoint. Bookmark the permalink.

Leave a comment