Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Environment: SP2010 Enterprise SP1, Server/SQL 2008 R2, VS2012

When building alerts through object model, what is the longest or most complex CAML filter that can be applied to them? Can they be as complex as I want, or is there a set number or other practical limit (like performance impact) that restricts them?

For example, this is a valid filter that specifies a certain folder and all its sub-folders:

@"<Query>" +
    @"<Or>" +
        @"<Eq>" +
            @"<FieldRef Name='ItemFullUrl'/>" +
            @"<Value Type='string'>" + fullPath + @"</Value>" + //Everything in the folder
        @"</Eq>" +
        @"<BeginsWith>" +
            @"<FieldRef Name='ItemFullUrl'/>" +
            @"<Value Type='string'>" + fullPath + @"/</Value>" + //Everything in sub-folders
        @"</BeginsWith>" +
    @"</Or>" +
@"</Query>";

But what if I strung a dozen of those together with <Or> statements to make it cover multiple directories?

Edit: Bonus question, how deep can you nest something in the filter? The GUI never lets you go down more than one level (<And><Or></Or></And>) but is it possible to do more?

Thanks for any help you can provide!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It seems unlikely that they did not reuse the Query parser from the list/view/query in the web services. IF that is the case you could experiment your way into the answer using this tool: http://www.codeproject.com/Articles/458008/CAML-Query-Builder

Point it at the list you want to target and make the most complex query you need and see how it works. Once again, I suppose I am just providing the way I would find an answer to your question, not really answering it.

Jon

share|improve this answer
    
I've actually been trying to use that, but I can't get it to connect to my test site properly. I point it to http://localhost/path/site and use site admin credentials, but under "Lists" the only things that appear are the various galleries and wfpub. Do you know what I'm doing wrong here? (For the record, it shows those same lists no matter what part of the server I point it to.) –  thanby Feb 1 '13 at 16:42
    
Also, though it may not technically be an answer, your theory about the query parser being reused certainly makes sense and thus far seems to be true. I have strung together a fairly complex filter and it appears to work, albeit at an impact to speed. –  thanby Feb 1 '13 at 20:15
1  
Oh good, you got that tool working. I just saw your comment. I don't think I would be all that surprised if you can take your server to its knees in a CAML stampede before hitting a physical limit to the depth of your query. It is easier for CAML to go through the eye of the needle than for a rich text editor to... –  ghangas Feb 4 '13 at 16:36
add comment

Your Answer

 
discard

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.