The User Profile is the central concept behind the personalization features of SharePoint (MOSS only). In addition to the User Profile, each user can have a My Site. A My Site is composed of:

  • A Profile Page that shows the user profile data, according to the user viewing it and the privacy options of each profile field. You can find that page (Person.aspx) in the root web site of the My Site host site collection (e.g http://mysites/Person.aspx?accountname=domain\username).
  • A Personal Site which is a site collection where you can show personal and public information and documents.

The Personal Site is automatically provisioned for you when you try to access your My Site (using the My Site link or clicking your username). However, you might want to create it programmatically for one or more users, before they even try to access it. See below an example of how to do it.

// open a site collection
using (SPSite site = new SPSite("http://myportal"))
{
    // get the server context
    ServerContext context = ServerContext.GetContext(site);

    // create the profile manager object
    UserProfileManager profileManager = new UserProfileManager(context);

    // get the user profile
    UserProfile profile = profileManager.GetUserProfile("domain\\username");

    // create the user's personal site
    profile.CreatePersonalSite();
}

The really important line of code here is the last one. There rest was already explained in one of my previous posts (WSS Tip #20: Get User Profile).

LEAVE A REPLY

Please enter your comment!
Please enter your name here