Check that a user has a SharePoint MySite

First follow the steps to create a console application for working with SharePoint 2007 Social Computing features

Now that you have your application ready to go you can display users that already have a MySite using the code below.

Display Users that have a MySite

//Get the site associated with the users
using (SPSite spSite = new SPSite(@http://localhost))
   //Create the server context because you are in a console application
   ServerContext siteContext = ServerContext.GetContext(spSite);
   UserProfileManager pmManager = new UserProfileManager(siteContext);
   foreach (UserProfile spUser in pmManager)
      if (spUser.PersonalSite != null)
         using(SPSite personalSite = spUser.PersonalSite)
            //Use SPSite like a normal site
            Console.WriteLine("personalSite.Url: " + personalSite.Url); 

You can see that once you have the site you could use it to check document libraries or any other action you would perform on an SPSite.

Addition Resources

sharepoint-pro For an in-depth look at the API and programmatically using the Social Computing features of SharePoint 2007 check out chapter 8 of Professional SharePoint 2007 Development

Digg It!  StumbleUpon  Reddit  Del.icio.us  NewsVine  Furl  BlinkList  Ma.gnolia  Technorati

» Trackback URL to this Post



#1 Karine on 6.04.2009 at 2:28 PM

Hi Brandon,

following the Dispose() Patterns of Roger Lamb (http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_400) the code

SPSite personalSite = spUser.PersonalSite;

will leave you with a memory leak

Kind regards,


#2 bschwartz on 6.04.2009 at 2:34 PM

Yes I was trying to make the example as small as possible to show that you can get the SPSite object and check. I will update the post.


#3 saumil on 7.09.2009 at 5:50 AM

Programming with MySite in sharepoint