Skip to content

Instantly share code, notes, and snippets.

@garima2510
Last active August 29, 2015 14:07
Show Gist options
  • Save garima2510/e7e1883de798a84ea70a to your computer and use it in GitHub Desktop.
Save garima2510/e7e1883de798a84ea70a to your computer and use it in GitHub Desktop.
Check If My Site Exists
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