CAML query not adding fields
See original GitHub issueCategory
- 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:
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
- 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;
}
- Put break point on
var a = item
- Inspect
item
variableValues
property
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:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It worked! This time I got a lot more values and also my custom properties:
Thank you, @jansenbe 😊
I just noticed, based on the images here, that
LoadItemsByCamlQueryAsync
returnsFileSystemObjectType
, butLoadListDataAsStreamAsync
returnsFSObjType
. Interesting.