SharePoint Tip #22: Create a User Profile

The best way to create SharePoint User Profiles is to import them from somewhere (Active Directory for instance). This is specially true if you want to create a lot of them at once. However, if you really want to do it manually, one at a time, you can. Just do it like in the snippet below.

// 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 upm = new UserProfileManager(context);

    // create the user profile
    UserProfile profile = upm.CreateUserProfile("domain\\username");

Just like getting a User Profile from the User Profile Store, to create one you need a UserProfileManager object. After that, you just need to call the CreateUserProfile method and pass it the user account name (including the domain).

Attention: User Profiles are a MOSS only feature. You cannot use them with WSS.