AnswerBun.com

SPListItemCollection to Dictionary

Rather than repeatedly query a SharePoint list for information I need, I wanted to create a dictionary from an SPListItemCollection (where the dictionary key is the “Title” value of each SPListItem, and the value is the SPListItem itself). I tried this:

SPListItemCollection documentCodesListItems = documentCodesList.GetItems(query);

Dictionary<string, SPListItem> dictionary = (from SPListItem i in documentCodesListItems select new { Key = i.Title, Value = (SPListItem)i }).ToDictionary(
                a => a.Key,
                a => a.Value);

But I get "Value does not fall within the expected range." exception. Can anybody see my mistake, or should I do this differently?

SharePoint Asked by K. Jones on December 24, 2020

1 Answers

One Answer

I was able to reproduce following error when my CAML query is wrong. So it's time to re-check your CAML query again.

Value does not fall within the expected range.

Generating Dictionary from items is perfect. You have to consider following thing while generating Dictionary from items where Title is the Key of Dictionary.

Keys can not be duplicate for Dictionary

Use u2u caml builder for building CAML query

Answered by Atish Dipongkor - MVP on December 24, 2020

Add your own answers!

Related Questions

sharepoint application deployment error

1  Asked on December 19, 2021 by faisaljanjua

 

How to create content fields and use in new page layout.?

1  Asked on December 17, 2021 by abhijeet-pawar

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.