1

Ok i am using a Caml Query to retrieve a item from a sharepoint list. I get the item loop through the field values to the one i want. My problem is i need to convert that which is a FieldUserValue Datatype to a normal User datatype. There is a method to retrieve FieldUserValue from User but not the other way around...

 User Usr;


        foreach (ListItem item in items)
        {
            foreach (var f in item.FieldValues)
            {
                if (f.Key == "ColumnTitleofDataTypePersonorGroup")
                {
                    //Error Message
                    Usr = f.Value;
                }
            }

        }

The Detailed ErrorMessages says Error 2 Cannot implicitly convert type 'object' to 'Microsoft.SharePoint.Client.User'. An explicit conversion exists (are you missing a cast?)
I think I am just missing something obvious.. Thanks for any help in advance..

user3753693
  • 225
  • 1
  • 5
  • 13

1 Answers1

6

The following example demonstrates how to get User object from FieldUserValue object:

var list = ctx.Web.Lists.GetByTitle(listTitle);
var item = list.GetItemById(itemId);
ctx.Load(item);
ctx.ExecuteQuery();

var author = (Microsoft.SharePoint.Client.FieldUserValue) item["Author"];
var authorUser = ctx.Web.SiteUsers.GetById(author.LookupId);
ctx.Load(authorUser);
ctx.ExecuteQuery();
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • Could you please help me with this question : https://stackoverflow.com/questions/53893774/how-to-manage-client-context-object-in-seperate-class-library – I Love Stackoverflow Dec 22 '18 at 07:29