MySite Url via UserProfile

UserProfile has the two property members for retrieving the Url for the User. Those propertis returns the MySite Url and Personal Site url for the User.

Here, i am adding some code snippets, which gets these Url values from MySite.

Using(SPSite _site = new SPSite("http://localhost"))
{
SPServiceContext context = SPServiceContext.GetContext(_site);
UserProfileManager profileManager = new UserProfileManager(context);
string UAccount = "DomainName\\spuser";

//Getting the UserProfile based on the User's Login Name
UserProfile u = profileManager.GetUserProfile(UAccount);
//Getting the User's Personal Site(Site Collection created for User's MySite) Url
Console.WriteLine("My Content Url: " + u.PersonalUrl.ToString());
//Getting the User's MySite Url
Console.WriteLine("My Site Url: " +u.PublicUrl.ToString());
}

RESULT:
My Content Url: http://localhost/my/personal/spuser/
My Site Url: http://localhost/my/Person.aspx?accountname=DomainName\spuser

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>