SharePoint 2007 (MOSS) allows you import profiles as a primary source in 2 different ways: using Active Directory o LDAP imports. Remeber that this are the only ways to perform this task. But when comes to update a profile's properties you can choose if you want to use Shared Services defining new import connections or using the SharePoint's object model. This post will cover only the programmatical way to update profile's properties: this is a much faster way than writing a new Buisness Data Catalog (BDC) application. A valid alternative to Buisness Data Catalog (BDC) is to create a simple Console Application and add it into your server's farm scheduled tasks,or, if you prefer, you could create a SharePoint's Timed Job which will be executed whenerver you want. Next, I will cover how to retrive user's UserProfile object and how to update it.
Here's the code snipped:
using (SPSite site = new SPSite("http://YOUR_SITE_URL")
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager userManager = new UserProfileManager(context);
UserProfile userProfile = userManager.GetUserProfile("DOMAIN\\USERID");
if (userProfile != null)
{
userProfile["Property1"].Value = "Your propery value";
userProfile["Property2"].Value = "Your propery value";
userProfile.Commit();
}
}
Simple right?
Most organizations, stores user's properties in Active Directory but they can also store some of this properties into SQL tables. You can merge all those properties in SharePoint's profiles and have them all without messing around with BDCs. The next method will return a DataTable and with the collaboration of the first snippet, you can easly build your own SharePoint's profile updater:
private static DataTable ReadTable(string dataTableName, string connectionString, string query)
{
DataTable dataTable = new DataTable(dataTableName);
try
{
SqlDataAdapter dataAdapter = new SqlDataAdapter(query,
connectionString);
dataAdapter.Fill(dataTable);
dataAdapter.Dispose();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
return dataTable;
}
Read this article to understand how can you build you SharePoint's timed job and merge it with this two simple snippets.