1

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());
  • 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
1

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.

0

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.

  • 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

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.