Create MySite Programmatically:

SharePoint provides APIs to create MySite programmtically. UserProfile object provides a method to create personal site.

Following console application creates MySite for a given account:

using Microsoft.Office.Server;

using Microsoft.Office.Server.Administration;

using Microsoft.Office.Server.UserProfiles;

using Microsoft.SharePoint;

using System.Web;

namespace UserProfileCreate

{

class Program

{

static void Main (string[] args)

{

using (SPSite site = new SPSite("http://servername"))

{

ServerContext context = ServerContext.GetContext(site);

UserProfileManager profileManager = new UserProfileManager(context);

string accountName = "domainname\\username";

UserProfile userProfile;

if (profileManager.UserExists(accountName))

{

userProfile = profileManager.GetUserProfile(accountName);

userProfile.CreatePersonalSite();

}

}

}

}

}

Comments

Popular posts from this blog

Adding Contact Selector Control to InfoPath form

Adding Validation to a Custom NewForm.aspx in SharePoint & Redirect

How to add to Sub-Sub Menu in SharePoint