Last active
August 29, 2015 14:07
-
-
Save garima2510/9d5736c70dbfe7bb318a to your computer and use it in GitHub Desktop.
Get My Site Url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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