Skip to content

Instantly share code, notes, and snippets.

@garima2510
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garima2510/9d5736c70dbfe7bb318a to your computer and use it in GitHub Desktop.
Save garima2510/9d5736c70dbfe7bb318a to your computer and use it in GitHub Desktop.
Get My Site Url
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using (ClientContext clientContext = new ClientContext("https://tenant.sharepoint.com/"))
{
SecureString passWord = new SecureString();
foreach (char c in "your_password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("your_email_id", passWord);
//This is the login name or account name of user whose my site url is needed
string loginName = "i:0#.f|membership|email_id_of_user_whose_my_site_is_needed";
PeopleManager peopleManager = new PeopleManager(clientContext);
PersonProperties properties = peopleManager.GetPropertiesFor(loginName);
clientContext.Load(properties, p => p.PersonalUrl, p => p.UserProfileProperties);
clientContext.ExecuteQuery();
Console.WriteLine("My Site Url is: " + properties.PersonalUrl);
Console.ReadLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment