4

I use following method to retrieve URL of personal site:

    private string GetPersonalSite(SPSite site)
    {
        var curUser = SPContext.Current.Web.CurrentUser;
        ServerContext context = ServerContext.GetContext(site);
        UserProfileManager upm = new UserProfileManager(context);
        UserProfile profile = upm.GetUserProfile(curUser.LoginName);
        return profile.PersonalUrl.AbsoluteUri;
    }

However, ServerContext class is deprecated.

ServerContext is obsolete. Use SPServiceContext.

Could you explain me, how to retrieve personal site from SPServiceContext?

2
private string GetPersonalSite(SPSite site)
{
    var curUser = SPContext.Current.Web.CurrentUser;
    SPServiceContext context = SPServiceContext.GetContext(site); 
    UserProfileManager upm = new UserProfileManager(context);
    UserProfile profile = upm.GetUserProfile(curUser.LoginName);
    return profile.PersonalUrl.AbsoluteUri;
}

that should work! same consept just changed ServerContext to SPServiceContext ;)

both have the same spsite context retrival!

http://msdn.microsoft.com/en-us/library/ee546948.aspx

http://msdn.microsoft.com/en-us/library/office/ms499329.aspx

|improve this answer|||||
4

Use SPServiceContenxt

 SPServiceContext serverContext = SPServiceContext.GetContext(mySite);    
 //Create an instance of the User Profile Manager
 UserProfileManager profileManager = new UserProfileManager(serverContext);
|improve this answer|||||
  • I only see one down-vote and three upvotes. – Benny Skogberg Jan 30 '14 at 10:24
  • But nobody posted a feedback on why I am being down-voted? – Falak Mahmood Jan 30 '14 at 19:04
  • It's how the system works. You are allowed to anonymously down-vote posts, even if I feel it's wrong. We (mods) can't see who voted on which post. – Benny Skogberg Jan 30 '14 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.