Retreive User Profile Properties by using .NET CSOM in Office 365 / SharePoint Online

using System.Text;

using System.Threading.Tasks;

using System.Security;

using Microsoft.SharePoint.Client;

using Microsoft.SharePoint.Client.UserProfiles;


namespace UserProfileCSOM
{
class Program
{
static void Main(string[] args)
{
const string serverUrl = "<<Site Url>>";
           
ClientContext cltContext = new ClientContext(serverUrl);

var userAccountName = "i:0#.f|membership|test@test.com";

var myUserName = "test@test.com";

var myPassword = "*****";

var secureStringPassword = new SecureString();

myPassword.ToList().ForEach(c => secureStringPassword.AppendChar(c));
 
var creds = new SharePointOnlineCredentials(myUserName, secureStringPassword); // Requires SecureString() for password



cltContext.Credentials = creds;
PeopleManager pplManager = new PeopleManager(cltContext);

PersonProperties prsnProperties = pplManager.GetPropertiesFor(userAccountName);


cltContext.Load(prsnProperties, p => p.AccountName, p => p.UserProfileProperties);

cltContext.ExecuteQuery();
foreach (var property in prsnProperties.UserProfileProperties)
{
Console.WriteLine(string.Format("{0}: {1}", property.Key.ToString(), property.Value.ToString()));
}
Console.ReadKey(false);

}

}

}







Result:

 

Comments

Popular posts from this blog

Run Powershell script on Remote Computer/Server

Power BI Refresh Issue: unable to convert the value '' from the source data type 'VT_BSTR' to the expected data type 'VT_I8.

SPDActivities - DP.SharePoint.Workflow - Workflow failed to run