SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I've read all the whitepapers, and I know that you can store up to 5 million list items in a list as long as you use folders.

What I'm after, is, has anyone written some nice recursion that gets a list, looks at all the folders in the list, and assigns list items either to a <2000 folder, or creates a new folder if one does not exist, and then stores list items there?

Same thing with list item retrival. Does anyone have a nice clean and fast method for getting all list items from a list <2000 at a time?

I've looked on google and here and haven't found a nice definitive guide for storing and retrieving list items from large lists with code samples, it's all been about the theory from what I can see.

share|improve this question
up vote 4 down vote accepted

That is because the operations you mentioned are all performed the exact same way as with smaller lists. My take is:

  1. Always use SPQuery (single list query) or SPSiteDataQuery (along with CrossListQueryCache) for cross-list query (in the same site collection) or CoreSearchResults (or KeywordQuery for direct call) to get across Site Collections.
  2. Use the same SPQuery to retrieve only those items you are interested in and once received make sure it is a FOLDER (by retrieve its Folder property and check for NULL) and start creating list items passing to it - others use the RootFolder to start writing in the root of the list.

In addition to that there are really many examples to write to lists which should serve your purpose with the above. Let me know if you need more details or examples.

Hope it helps, C:\Marius

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.