Sharepoint: Create MySite Programmatically

CodeKeep C# Feed Novembre 13th, 2008

Description: How to create mysite programmatically

Link: http://www.codekeep.net/snippets/0609b2f5-bff3-4b8c-8b1a-02e6a840f680.aspx

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(); 

}
}
}
}
} 

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comments are closed.

Trackback URI |