Retrieving Limited ListItem Information from a SharePoint List using GraphServiceClient in C#

Mandy Hodges
2 min readJun 2, 2023

--

In my Blazor Server Application, I want to retrieve just a list of Ids and Titles for a SharePoint List to use as the options in a select list.

Here is how you go about it.

This code assumes you already have a GraphServiceClient with the appropriate authentication token etc.

var response = await client
.Sites[SiteId]
.Lists[ListId]
.Items
.Request()
.Expand("Fields($select=Title)")
.Select("Id, Fields")
.GetAsync();

foreach(var item in response)
{
Console.WriteLine($"{item.Id} - {item.Fields.AdditionalData["Title"]}");
}

The key takeaways here are as follows:

.Expand("Fields($select=Title)")

This tells the system to include additional columns to the normal Id, Created By etc. All those additional columns are stored in “Fields”. However, instead of retrieving ALL of the columns, I only want the one called “Title”.

.Select("Id, Fields")

This tells the system not to bother sending all the other information, just the Id and the Fields. The expand line has told it to only include the Title column from the Fields, so objective achieved!

When I debug, you can see what is returned by looking at the response:

To see how to access the items once you have them:

foreach(var item in response)
{
Console.WriteLine($"{item.Id} - {item.Fields.AdditionalData["Title"]}");
}

The normally returned information (in my case the Id) is obtained directly with the dot notation on the item.

The column information (in my case the Title from Fields) is obtained by item.Fields.AddtionalData[“Title”] as Title is the key from the Additional Data Dictionary held in the FieldValueSet.

Like any similar article, I write for my own future reference and hope that someone else may also gain a benefit.

I am more than happy for people to correct any mistakes they see in my approach as I love to continually learn.

--

--

Mandy Hodges

Life-long learner with too many interests for one lifetime...