enter image description here

I want to get the list items where invoice _category is equal to "Service".

Please help?

Current code:

camelQuery.Viewxml = "<View><Query> <Where><Eq><FieldRef Name='Invoice_Category'/> <Value Type='Text'>Service</Value></Eq></Where><Query></View>"

It throws an error of string constant.

  • What is the data type of your column/field (invoice _category)? Commented Feb 17, 2020 at 6:59
  • 1
    The last <Query> element should terminate the first one -- it is missing a forward slash... Commented Feb 17, 2020 at 7:03
  • Yes, there are some syntax errors in CAML. refer below answer for complete query. Commented Feb 17, 2020 at 7:07

1 Answer 1


Try to use your CAML in below format:

                <FieldRef Name='Invoice_Category'/>
                <Value Type='Text'>Service</Value>


  1. In CAML query you need to use internal name of your column/field.

Find the internal name of SharePoint column

Complete Code:

string siteUrl = "http://tenant.sharepoint.com/sites/SiteName";  
ClientContext clientContext = new ClientContext(siteUrl);  
SP.List oList = clientContext.Web.Lists.GetByTitle("ListName");  

CamlQuery camlQuery = new CamlQuery();  
camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Invoice_Category'/><Value Type='Text'>Service</Value></Eq></Where></Query></View>";  

ListItemCollection collListItem = oList.GetItems(camlQuery);  


foreach (ListItem oListItem in collListItem) {  
    Console.WriteLine("ID: {0} \nTitle: {1}", oListItem.Id, oListItem["Title"]);  

Update from Comments:

Also, from the screenshot you attached in your question, I can see that the value in your column is "Service Invoice" and not just "Service". So in that case you might need to use Contains instead of Eq. check below query:

                <FieldRef Name='Invoice_Category'/>
                <Value Type='Text'>Service</Value>

Reference: Query schema.

  • options strics on disallows implicit conversions from system.xml.linq.xelement to string error is there
    – user89072
    Commented Feb 17, 2020 at 7:08
  • Try using the code given in my updated answer. let me know if this works for you. Or you can add the complete code you are using to get list items to your question. Commented Feb 17, 2020 at 7:11
  • ',' expected error
    – user89072
    Commented Feb 17, 2020 at 7:15
  • actualy we have an invoice list in which to get the information of the service from the invoice category coloumn
    – user89072
    Commented Feb 17, 2020 at 7:18
  • At which code line you are getting this error? Also, what is the data type and internal name of your "Invoice_Category" column? Can you please add the screenshot of column settings for Invoice_Category column? (Go to list settings-->navigate to columns section-->click on the Invoice_Category column name-->take screenshot-->Edit your question-->attach image). Commented Feb 17, 2020 at 7:24

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