0

I managed to access user profile content:

    using (SPSite ospSite = new SPSite("http://localhost:80/"))
    {
        ServerContext s = ServerContext.GetContext(ospSite);
        UserProfileManager profileManager = new UserProfileManager(s);
        UserProfile p = profileManager.GetUserProfile("some_user");

        // e.g. responsibility retrieval
        var r = p["SPS-Responsibility"];
        var responsibilities = r.GetTaxonomyTerms();
    }

But I don't know how to access users' blog posts collection.

Any advice?

vovafeldman
  • 585
  • 10
  • 17

1 Answers1

4

Use the PersonalSite property of UserProfile object to retrieve the user's My Site.

In the SPSite loop through, child SPWeb objects which are of template "Blog". Check out the templates names here:

http://blogs.msdn.com/b/richin/archive/2011/07/04/sharepoint-2010-site-template-names.aspx

Once you find the blog site, you can simply access the items in "Posts" List of the SPWeb object.

Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
  • As soon as I'm trying to iterate through child SPWeb objects by: `profile.PersonalSite.OpenWeb().Webs` or `profile.PersonalSite.AllWebs` I'm getting `System.UnauthorizedAccessException` exception even though I'm running the process as Administrator. Any advice? – vovafeldman Jul 29 '11 at 20:30
  • Just found the solution, just need to execute it with elevated privileges: `SPSecurity.RunWithElevatedPrivileges(() => { _some.code.here_ });` – vovafeldman Jul 29 '11 at 20:44