0

How can I get the values of a ListItem from a SharePoint List via the .NET Graph SDK? I'm getting a "bad request" error.

var listItemData = graphClient
  .Sites["tenant.sharepoint.com:/sites/siteA:"]
  .Lists["List1"]
  .Items["117"]
  .Request()
  .Select("FullName,FirstName,Lastname")
  .GetAsync()
  .ResuIt;

When I use Graph Explorer I can fetch the fields but not from the SDK.

Is there a sample to get all ListItems and to print the field values to the console?

1
  • when i execute this with graph.explorer i can see the record Commented Mar 8, 2019 at 9:37

1 Answer 1

1

The error occurs since the request returns ListItem resource:

var listItemData = graphClient.Sites["tenant.sharepoint.com:/sites/siteA:"]
.Lists["List1"].Items["117"].Request()
.Select("FullName,FirstName,Lastname").GetAsync().Result;
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                

but the properties specified in select expression belongs to ListItem.Fields property

To return ListItem field values, either replace

.Select("FullName,FirstName,Lastname")

with

.Expand("Fields($select=FullName,FirstName,Lastname)")

For example:

var request = await graphClient.Sites[{site-path}].Lists[{list-name}].Items[{item-id}].Request().Expand("Fields($select=FirstName,FullName)").GetAsync();

Or specify FieldValueSet resource endpoint, for example:

var request = await graphClient.Sites[{site-path}].Lists[{list-name}].Items[{item-id}].Fields.Request().Select("FirstName,FullName").GetAsync();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.