3
votes

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!

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
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
Approximately how many items are in the library? In each folder? - Kit Menke
Also, can you elaborate on what exactly you're trying to do? It sounds like we could probably recommend a better approach. - Kit Menke

2 Answers

2
votes

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;
    }));
1
votes

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