Last active
August 29, 2015 14:07
-
-
Save garima2510/e7e1883de798a84ea70a to your computer and use it in GitHub Desktop.
Check If My Site Exists
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); | |
//code to get personal space property | |
foreach (var property in properties.UserProfileProperties) | |
{ | |
if (property.Key.ToString().ToLower().Equals("personalspace")) | |
{ | |
Console.WriteLine("Perosnal Space: " + property.Value); | |
} | |
} | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment