0

I am having this problem where I need to get some specific properties of a user profile using CSOM but I do not get any property.

This is the code I am working with:

UserProfilePropertiesForUser profilePropertiesForUser = new
                UserProfilePropertiesForUser(ctx, targetUser, proper.ToArray());
ctx.Load(profilePropertiesForUser);
ctx.ExecuteQuery();
IEnumerable<string> profilePropertyValues = 
                peopleManager.GetUserProfilePropertiesFor(profilePropertiesForUser);
foreach (var propVal in profilePropertyValues)
{

when inside the foreach, I can see that no properties were found, Please Help.

1 Answer 1

0

Try it as below:

    const string serverUrl = "http://serverName/";  
const string targetUser = "domainName\\userName";  

// Connect to the client context.
ClientContext clientContext = new ClientContext(serverUrl);

// Get the PeopleManager object.
PeopleManager peopleManager = new PeopleManager(clientContext);

// Retrieve specific properties by using the GetUserProfilePropertiesFor method. 
// The returned collection contains only property values.
string[] profilePropertyNames = new string[] { "PreferredName", "Department", "Title" };
UserProfilePropertiesForUser profilePropertiesForUser = new UserProfilePropertiesForUser(
    clientContext, targetUser, profilePropertyNames);
IEnumerable<string> profilePropertyValues = peopleManager.GetUserProfilePropertiesFor(profilePropertiesForUser);

// Load the request and run it on the server.
clientContext.Load(profilePropertiesForUser);
clientContext.ExecuteQuery();

// Iterate through the property values.
foreach (var value in profilePropertyValues)
{
    Console.Write(value + "\n");
}
Console.ReadKey(false);
1
  • yes, this helped me see the problem, I was loading the properties before they were needed to be loaded, and so the values never came back, Thanks a lot..
    – jvr
    Dec 15, 2016 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.