Last week I got the question if it would be possible to automatically create the My Site for a specific user in SharePoint Server 2007. Normally the My Site gets created when the user accesses it for the first time. I got a some advice from a fellow MVP - Pierre but when I looked at it a little more closely I noticed that some of the classes used in SharePoint Portal Server 2003 are now obsolete.
public static void CreatePersonalSite(string sAccount)
{
//get portal site context from topology
string strUrl = "http://moss";
//TopologyManager Obsolete
TopologyManager tm = TopologyManager();
PortalSite ps = tm.PortalSites[new Uri(strUrl)];
PortalContext pc = PortalApplication.GetContext(ps);
//initialize user profile config manager object
UserProfileManager upm = UserProfileManager(pc);
UserProfile u = upm.GetUserProfile(sAccount);
u.CreatePersonalSite();
}
So how does the code look like using the new SharePoint Server 2007 object model.
public static void CreatePersonalSite(string sAccount)
{
using (SPSite site = new SPSite("http://moss"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile u = profileManager.GetUserProfile(sAccount);
u.CreatePersonalSite();
}
}
tags: sharepoint, sharepoint2007, sharepoint+2007, moss, csharp
4 comments:
thanks for this post :-)
Pierre
Just for anyone else trying to implement this - this requires a reference to Microsoft.Office.Server (in the 12 hive/ISAPI folder)
Oskar
http://SharePointSearch.info
where would you put this code?
You could create a console app and run this on the server itself
Post a Comment