0

I am trying to retrieve and change a property of a non-admin user called User1. Tried retrieving user profiles using this:

using (ClientContext tenantContext = new ClientContext("https://yoursite-admin.sharepoint.com/ This link is external to TechNet Wiki. It will open in a new window. "))
            {
            SecureString passWord = new SecureString();
            foreach (char c in "yourpassword".ToCharArray())
                passWord.AppendChar(c);
            tenantContext.Credentials = new SharePointOnlineCredentials("geetanjali@yoursite.onmicrosoft.com", passWord);
PeopleManager peopleManager = new PeopleManager(tenantContext);
peopleManager.SetSingleValueProfileProperty(user.LoginName, user.Property, user.PropertyValue);
tenantContext.ExecuteQuery();

Connecting to the tenant-admin site I can perform operations on users, such as SetSingleValueProfilePropertybut these are never all user profiles. The tenant admin site seems to contain only admins. Hence using here a correct User1 login name, I receive User Profile Error 1000: User Not Found: Could not load There are no issues with retrieving/editing profile properties of admin users.

Having received the error, I followed this logic: "The only site that contains all users is tenant-my.sharepoint.com".

using (ClientContext tenantContext = new ClientContext("https://yoursite-my.sharepoint.com/ This link is external to TechNet Wiki. It will open in a new window. "))
            {
            SecureString passWord = new SecureString();
            foreach (char c in "yourpassword".ToCharArray())
                passWord.AppendChar(c);
            tenantContext.Credentials = new SharePointOnlineCredentials("geetanjali@yoursite.onmicrosoft.com", passWord);
PeopleManager peopleManager = new PeopleManager(tenantContext);
peopleManager.SetSingleValueProfileProperty(user.LoginName, user.Property, user.PropertyValue);
tenantContext.ExecuteQuery();

Fantastic. I managed to retrieve all user profiles. However, when I tried to perform operations on users, such as SetSingleValueProfileProperty, I receive "Access denied. You do not have permission to perform this action or access this resource".

Question: How to change User1 profile properties?

1

I had the same issue. Turns out the solution for me was to create two contexts; one to the site holding the users I want to edit and another to the admin site.

The admin site context has permissions to edit users while the site context holds the (most) complete list of user profiles.

There seems to be no way to directly retrieve all user profiles from UPS through CSOM(please correct me if I'm wrong!).

Let me know if you need an elaboration :)

1

User profiles are not stored in Site Collections, rather the user profile service.

The Patterns & Practices group has two samples showing how to read and update User Profiles:

https://github.com/OfficeDev/PnP/tree/master/Samples/UserProfile.Manipulation.CSOM

https://github.com/OfficeDev/PnP/tree/master/Samples/UserProfile.Manipulation.CSOM.Console

  • Thanks, but my point is that if I am connecting to tenant-admin.sharepoint.com and looking for a particular user who is not an administrator, I receive "user profile not found", so these links do not show how to get access to all of my users' profiles. – grisha Apr 4 '15 at 18:18
  • Well, your question shows only the code to establish context. We have no idea what code you are using to read profiles. – Paul Schaeflein Apr 6 '15 at 20:09
  • Hey, I edited the question to make it more specific. I don't think the issue is with the code itself, it executes correctly against all admin users. The question is where to find and edit a non-admin User1. If you have any more questions, let me know. – grisha Apr 7 '15 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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