3

I'm trying to retrieve both a file's Id in its list, plus its ETag, using the following snippet;

using (var clientContext = new ClientContext(webUrl))
{
    var results = clientContext.Web.Lists
        .GetById(listId).RootFolder.Files;

    clientContext.Load(results, files => files
            .Include(file => file.ETag)
            .Include(file => file.ListItemAllFields.Id));

    clientContext.ExecuteQuery();
    foreach (var file in results)
    {
        Console.WriteLine(file.ETag + " " + file.ListItemAllFields.Id);
    }
}

However, I'm getting the following exception;

The query expression 'files => files.Include(new [] {file => file.ETag}).Include(new [] {file => Convert(file.ListItemAllFields.Id)})' is not supported.

Am I forming my query correctly? It seems that if I query for the ETag by itself, then the query works. And also, if I query for the ListItemAllFields.Id by itself, then the query works.

It's when they are both included in the one query that the failure occurs.

6

Managed to work this one out with a bit of trial and error. The correct form of the query is;

clientContext.Load(results,
    files => files.Include(file => file.ETag),
    files => files.Include(file => file.ListItemAllFields.Id));

Hopefully that's of some use to anyone else who encounters this issue.

3
  • Yes this is right. Also this same thing can help you get a Folder itemId. – Nicholas DiPiazza Jul 17 '19 at 2:13
  • 2
    I knew it would be useful to someone! Didn't know it would be 7 years later, but worth it :) – C.McAtackney Jul 18 '19 at 11:04
  • 1
    yeah when you contribute to stack exchange, you will be someone's hero 1,000's of miles away many years later. – Nicholas DiPiazza Jul 18 '19 at 14:10

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.