question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CAML query not adding fields

See original GitHub issue

Category

  • Bug

Describe the bug

I would like to get some list item fields by using CAML query, but the fields don’t get returned to me, specifically, I’m trying to get FileRef and FileLeafRef fields for list item. When I execute await list.LoadItemsByCamlQueryAsync(query) and iterate over item collection, then I see only these properties in item.Values collection: image CAML query used to get the result:

<View>
    <ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /></ViewFields>
</View>

Maybe I’m expecting from it what it shouldn’t do? If so, then how could I get FileRef field value for my items?

Steps to reproduce

  1. Execute code:
using var ctx = await pnpContextFactory.CreateAsync(new Uri(notification.SiteUrl));
var query = @"
<View>
    <ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /></ViewFields>
</View>
";
IList list = await ctx.Web.Lists.GetByIdAsync(new Guid(notification.Resource));
await list.LoadItemsByCamlQueryAsync(query);
foreach (var item in list.Items.AsRequested())
{
  var a = item;
}
  1. Put break point on var a = item
  2. Inspect item variable Values property

image

Expected behavior

I should see under Values property FileRef and FileLeafRef as with SharePoint REST API, when you add ?$select=FileRef,FileLeafRef to the request.

Environment details

  • SDK version: 1.1.0
  • OS: Windows 10
  • SDK used in: C# Azure Function
  • Framework: .NET Core v3.1
  • Browser(s): N/A
  • Tooling: Visual Studio 2019 Enterprise v16.9.4
  • Additional details: Project file:
<Project Sdk="Microsoft.NET.Sdk">
 <PropertyGroup>
   <TargetFramework>netcoreapp3.1</TargetFramework>
   <AzureFunctionsVersion>v3</AzureFunctionsVersion>
 </PropertyGroup>
 <ItemGroup>
   <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
   <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
   <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
   <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
   <PackageReference Include="PnP.Core" Version="1.1.0" />
   <PackageReference Include="PnP.Core.Auth" Version="1.1.0" />
 </ItemGroup>
 <ItemGroup>
   <None Update="host.json">
     <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
   </None>
   <None Update="local.settings.json">
     <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     <CopyToPublishDirectory>Never</CopyToPublishDirectory>
   </None>
 </ItemGroup>
</Project>

Additional context

N/A

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wonderplayercommented, Apr 16, 2021

It worked! This time I got a lot more values and also my custom properties:

item.Values.Keys
Count = 27
    [0]: "PermMask"
    [1]: "FSObjType"
    [2]: "HTML_x0020_File_x0020_Type"
    [3]: "UniqueId"
    [4]: "ProgId"
    [5]: "NoExecute"
    [6]: "ContentTypeId"
    [7]: "FileRef"
    [8]: "_UIVersion"
    [9]: "SMTotalSize"
    [10]: "File_x0020_Size"
    [11]: "_CommentFlags"
    [12]: "Site_x0020_news_x0020_flow_x0020_in_x0020_progress"
    [13]: "FileLeafRef"
    [14]: "Modified"
    [15]: "Landing_x0020_site_x0020_news"
    [16]: "ItemChildCount"
    [17]: "FolderChildCount"
    [18]: "A2ODMountCount"
    [19]: "_StubFile"
    [20]: "_ComplianceTag"
    [21]: "owshiddenversion"
    [22]: "_SPSitePageFlags"
    [23]: "ContentVersion"
    [24]: "DocConcurrencyNumber"
    [25]: "_VirusStatus"
    [26]: "Restricted"

Thank you, @jansenbe 😊

0reactions
DaleyKDcommented, May 5, 2021

I just noticed, based on the images here, that LoadItemsByCamlQueryAsync returns FileSystemObjectType, but LoadListDataAsStreamAsync returns FSObjType. Interesting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CAML: Possible to query non existing field?
You should use Nullable attribute in ViewFields property for fields, which are expected to exist only in few lists which are mentioned in ......
Read more >
CAML query not retrieving all fields using vb.net VS2019 ...
When the line of code runs to find item.("First Name") , I get the message that it is not in the list and...
Read more >
CAML Query to filter library not working as expected
below the is the CAML query i am using in my code for fetching data and binding to DATALIST control... _query.Query = "...
Read more >
Why Your CAML Query Might Be Returning No Results
If you are adding the columns manually or in a single content type, you need to ensure that the field(s) that you want...
Read more >
FieldRef element (Query)
In CAML, represents a reference to a field within a query. ... view definition and is not returned in a Fields enumeration inside...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found