3

I am running a sharepoint caml query where I want to check that a field on an item is equal to one of many values. I do this dynamically and may wish to check against many hundreds of values.

I found that when performing a query with 780 OR elements I got an error related to server memory. Obviously this is variable across environments, but I am looking for some guidelines suggesting a maximum query length to which I should cap.

Thanks!

Paul
  • 544
  • 4
  • 12
  • 2
    Jesus Christ, 780 ORs!? I don't want to begin to imagine the level of nesting that requires. Surely there's a better way to do what you're wanting to do... – James Love Mar 06 '11 at 22:46
  • I have a list with many folders (folders were required for security purposes). Each folder may have many items with in. I want to run a query such as: get all items from 600 of 800 folders. I am currently doing this by checking the FileRef field on the items with a very large nested OR caml query. If you have a better suggestion, by all means, PLEASE let me know. – Paul Mar 07 '11 at 00:14
  • Approximately how many items are in the library? In each folder? – Kit Menke Mar 07 '11 at 14:46
  • Also, can you elaborate on what exactly you're trying to do? It sounds like we could probably recommend a better approach. – Kit Menke Mar 07 '11 at 14:48

2 Answers2

2

How about using ContentIterator? http://community.zevenseas.com/Blogs/Robin/Lists/Posts/Post.aspx?ID=122

It supports recursion for walking a tree of items and acting on them in some way. This code does a "publish all" on the style library files whose "FeatureId" properties match a particular value:

SPList styleLibrary = rootWeb.Lists.TryGetList("Style Library");
SPFolder folder = styleLibrary.RootFolder;
ContentIterator ci = new ContentIterator();
ci.ProcessFilesInFolder(
    styleLibrary,
    folder,
    true,
    new ContentIterator.FileProcessor((SPFile f) =>
    {
        // Check the FeatureId property the file's been "stamped" with
        if (f.Properties.ContainsKey("FeatureId"))
        {
            if (String.Equals(f.Properties["FeatureId"] as string, featureId, StringComparison.InvariantCultureIgnoreCase))
            {
                if (f.Level == SPFileLevel.Checkout)
                    f.CheckIn(String.Empty, SPCheckinType.MajorCheckIn);
                if (f.Level == SPFileLevel.Draft)
                    f.Publish("");
            }
        }
    }),
    new ContentIterator.FileProcessorErrorCallout((SPFile f, Exception Ex) =>
    {
        //Define the action I need to do if an error occur
        return false;
    }));
Eccentropy
  • 444
  • 1
  • 4
  • 11
  • That would solve my issue perfectly - but unfortunately I have to work within the constraints of MOSS; the content iterator is a SharePoint 2010 feature. I should have stated that. Still +1. – Paul Mar 08 '11 at 00:10
  • @Paul, I'm sorry I should have asked first! Thanks. – Eccentropy Mar 09 '11 at 20:22
1

You could get all folders by SPList.Folders, iterate over the folders and filter it by whatever...

Matthias
  • 1,032
  • 8
  • 21
  • This is the case I am trying to avoid: it would require a query for every folder and hence would be inefficient. I would be better off getting SPList.Items and filtering the set directly. – Paul Mar 22 '11 at 21:46
  • SPList.Folders returns every Folder recursivly, which means subfolders also, so there's no need to query every folder separately. – Matthias Mar 23 '11 at 08:33