Convert Sharepoint ListItem to dictionary with specific columns only

Hi,

I have a loop of SharePoint list items
I use Msgraph to get items from SharePoint.
In the loop I have ListItem object which contains data from Sharepoint Item
I convert it to dictionary with the following code
ListItem.Fields.ToDictionary(Function(x) x.Name, Function(x) x.Value)
I receive dictionary of all fields.

I want to get only specific fields from ListItem object.
Do you know how to change my code to create a dictionary of only specific columns?
I keep the name of those columns in array
new string(){“Title”, “Instances”,“CCX_And_Description”,“ID”}


Thank you in advance

@mateusz.wojcik

Try this

ListItem.Fields.Where(function(x) arrayNames.Any(function(y) y.ToLower.Equals(x.Name.ToLower)).ToDictionary(Function(x) x.Name, Function(x) x.Value)

cheers

cheers

When above is working, we can try to filter (as one of many options)

Assign activity:
yourDict =

(From f in ListItem.Fields
Where YourColsetNameArrayVar.Contains(f.Name)
Select v=f).ToDictionary(Function(x) x.Name, Function(x) x.Value)

Hi @mateusz.wojcik

Try the below syntax:

selectedFieldsDictionary As Dictionary(Of String, Object) = ListItem.Fields.
    Where(Function(field) selectedColumns.Contains(field.Name)).
    ToDictionary(Function(field) field.Name, Function(field) field.Value)

Hope it helps!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.