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