Creating MySites Programmatically

Instead of asking every user to click on “My Site” and have the site provisioned for them it’s sometimes nice to already have the site created… or create it as part of the Employee Intake process. This is especially true if the My Site plays a role in a custom application as it did for one of my clients.

Here’s a snippet to get you started:

using (SPSite site = new SPSite(url))
{
UserProfileManager profileManger = new UserProfileManager(ServerContext.GetContext(site));
UserProfile profile = profileManger.GetUserProfile(@"domain\user");
profile.CreatePersonalSite();
}

However, I kept getting the following error message:
You do not have access to create this personal site.

Now.. I’m an admin on the box and within SharePoint but it turns out you will see this error if your user does not have access to Shared Services. You’ll either need to impersonate a higher user using SPSecurity or, in my case, simply right click on your command line application and choose “Run as…” and enter the credentials for your Shared Services administrator.

I'm a public speaker and the Chief SharePoint Architect for Eastridge, a Microsoft Gold Partner specializing in SharePoint and custom application development in Winston-Salem, NC. I focus on the SharePoint platform with a specialty in Information Architecture, Publishing and Best Practices.

Got something to say? Go for it!