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

Can someone tell me why the following CAML query is not filtering results? It's returning files that do not contain "/Internal/Bug 594" in their FileRef value. Thanks.

<View Scope='Recursive'>
    <RowLimit>1000</RowLimit>
    <Query>
        <And>
            <Eq>
                <FieldRef Name='FSObjType' />
                <Value Type='Text'>0</Value>
            </Eq>
            <Contains>
                <FieldRef Name='FileRef' />
                <Value Type='Text'>/Internal/Bug 594</Value>
            </Contains>
        </And>
    </Query>
</View>

And here's the code i'm using to execute this query:

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = [the query you see above];

//IEnumerator<ClientOM.List> LibsIterate = null;
ListItemCollection tempItems = LibsIterate.Current.GetItems(camlQuery);

//ClientOM.ClientContext clientContext = null;
clientContext.Load(tempItems);
clientContext.ExecuteQuery();

//List<ListItem> allItems = new List<ListItem>();
allItems.AddRange(tempItems.ToList());
share|improve this question
1  
Try converting <Value Type='Text'> to <Value Type='URL'> –  Arsalan Adam Khatri Dec 5 '12 at 14:24
1  
Also instead of FileRef, try using ServerUrl field with <Value Type='Text'> –  Arsalan Adam Khatri Dec 5 '12 at 14:40
add comment

2 Answers 2

Well, as you already guessed if the CAML query is not syntactically correct it will just run and return everything without applying any filters or ordering.

You don't get any exceptions and this is pretty counter-intuitive.

share|improve this answer
add comment

I think the problem is that the value of the FileRef field contains a space. Try replacing the space with %20 and see if it works.

share|improve this answer
2  
sigh It's missing the <Where></Where> clause. Thanks for the suggestions guys. I guess it ignores that whole <And> clause, and just runs it as <Query></Query>. –  Victor Dec 5 '12 at 19:12
3  
Please set that as an answer. And yes, when there is an issue with the query SP just returns all items. –  Robert Kaucher Jun 30 '13 at 1:02
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.