Tuesday, August 25, 2009

Create MySite Programmatically

Here is the code, which will create MySite for the user programatically

public
static void CreateMySite(string userId)
{
using (SPSite site = new SPSite("http://sharepointurl"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile userProfile = profileManager.GetUserProfile(userId);
userProfile.CreatePersonalSite();

}
}