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]

Try Out Code2care Dev Tools:


Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR -