Skip to content

Instantly share code, notes, and snippets.

@garima2510

garima2510/checkmysite.cs

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.