Tuesday, December 19, 2006

Automatic My Site creation with SharePoint 2007

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



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


tags: , , , ,



Anonymous said...

thanks for this post :-)


Unknown said...

Just for anyone else trying to implement this - this requires a reference to Microsoft.Office.Server (in the 12 hive/ISAPI folder)


Unknown said...

where would you put this code?

jopx said...

You could create a console app and run this on the server itself