I'm attempting to query for list items using a value stored in a plain text multi-line of text field in a SharePoint 2007 custom list.

My column is named FilePath and contains a value like: /admin/SiteCollection/Report Library/Reports/Corporate Reports/Final Audit Report [Dec-11].pdf

I would like to create a CAML query that will return this item. For example:

<Where><Eq><FieldRef Name="FilePath" /><Value Type="Text" >/admin/SiteCollection/Report Library/Reports/Corporate Reports/Final Audit Report [Dec-11].pdf</Value></Eq></Where>

Problem is... it doesn't work. We have seemingly narrowed it down to an issue with the square brackets. Duplicating the row and removing the square brackets lets us query for the item again.

How can I query for items using a multi-line of text file which contains square brackets?

Some more research:

  • Seems to work OK when a single line of text field contains square brackets
  • Using BeginsWith works ok: <Where><BeginsWith><FieldRef Name="FilePath" /><Value Type="Text" >/admin/SiteCollection/Report Library/Reports/Corporate Reports/Final Audit Report [Dec-11].pdf</Value></BeginsWith></Where>
  • Using Contains works ok: <Where><Contains><FieldRef Name="FilePath" /><Value Type="Text" >/admin/SiteCollection/Report Library/Reports/Corporate Reports/Final Audit Report [Dec-11].pdf</Value></Contains></Where>
  • I've tried encoding the square brackets (&#91;Dec-11&#93;) and using <![CDATA[]]>, both of which work in other queries, but do not help here.
  • Does it make any difference if you switch it to a contains and look for something like 11].pdf for testing purposes? social.technet.microsoft.com/Forums/en-US/… has some options. Jan 10, 2013 at 17:31
  • Just tested it and using Contains works fine...
    – Kit Menke
    Jan 10, 2013 at 19:11
  • Just curious if these CAML Building tools give you any insight. CAML doesn't support regex, but I wonder what the tools generate. msdn.microsoft.com/en-us/library/ff648040.aspx
    – Mike
    Jan 10, 2013 at 22:36
  • @Mike I tried it in U2U CAML Query builder and it did not encode the square brackets.
    – Kit Menke
    Jan 11, 2013 at 15:20

2 Answers 2


Same issue, but with "<".

Try use STSHtmlEncode in SP or there is an example with CDATA

<Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text"><![CDATA[Value < 10]]></Value></Eq></Where></Query>

How to query using CAML when a value has < in the value

  • 1
    I tried encoding the values but it didn't make a difference when using Eq (see my last bullet point in my question).
    – Kit Menke
    Jan 11, 2013 at 15:14

I haven't been able to figure out why Eq doesn't work.. so if anyone can figure that out feel free to post an answer and I will accept it.

The workaround is to use BeginsWith or Contains instead of Eq. In my case I think it will work because of how my data is structured but it is not ideal.

Example working queries:

<Where><BeginsWith><FieldRef Name="FilePath" /><Value Type="Text" >/admin/SiteCollection/Report Library/Reports/Corporate Reports/Final Audit Report [Dec-11].pdf</Value></BeginsWith></Where>

U2U query which also works:

<Where><Contains><FieldRef Name="FilePath" /><Value Type="Note">/admin/SiteCollection/Report Library/Reports/Corporate Reports/Final Audit Report [Dec-11].pdf</Value></Contains></Where>

Some other interesting info, you can encode the square brackets using their unicode value:

<Where><Contains><FieldRef Name="FilePath" /><Value Type="Note" >/admin/SiteCollection/Report Library/Reports/Corporate Reports/Final Audit Report &#91;Dec-11&#93;.pdf</Value></Contains></Where>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.