0

The Microsoft Best Practices for SharePoint guide recommends not enumerating entire SPList.Items collections or SPFolder.Files collections.

I have the need to generate a list of all files in the farm, but I'd like to do it in a way that's considered good practice. How should I approach this?

| improve this question | | | | |
  • why don't you just drop a List View Web Part ? – Arsalan Adam Khatri Sep 30 '13 at 9:26
  • does it matter in what way you do it? like in a webpart, application or through powershell? – Ali Jafer Sep 30 '13 at 10:27
2

Use SPQuery - you can limit ammount of retrieved items per request and add custom filters

SPList list = web.Lists["Your List Title"];
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope='RecursiveAll'";
// OPTIONAL // query.Query = "<Where><Eq><FieldRef Name='ContentTypeId' /><Value Type='ContentTypeId'>[Your Content Type ID]</Value></Eq></Where>";
query.RowLimit = 1000;
do
{
    SPListItemCollection itemColl = list.GetItems(query);
    foreach (SPListItem item in itemColl)
    {
        // DO YOUR STUFF
    }
    query.ListItemCollectionPosition = itemColl.ListItemCollectionPosition;
} while (query.ListItemCollectionPosition != null);
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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