error CAML Query containing special characters

error CAML Query containing special characters

If you are building a CAML Query to match a value that contains a special character like & (say SharePoint&InfoPath), you will receive an error, and the query will fail.

Resolution - Handle this the way you handle special characters in XML. Include your value within < ![CDATA[ value ]] >. Incorrect (throws error) -

<Eq><FieldRef Name="Title" /><Value Type="Text">SharePoint&InfoPath</Value></Eq>

Correct -

<Eq><FieldRef Name="Title" /><Value Type="Text"><![CDATA[SharePoint&InfoPath]]></Value></Eq>

In real scenarios, build your CAML Query by appending the value in the query, like

<Eq><FieldRef Name="Title" /><Value Type="Text"><![CDATA[ + value + ]]> </Value></Eq> [where value = text to be matched]


This is not an AI-generated article but is demonstrated by a human.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!