I am trying to check if a filename exists in the 'Name' column of Shared Docs Library. I think only CAML could help here. So I made this query

"<Where><Eq><FieldRef Name='Name' /><Value Type='Text'>" + docname + "</Value></Eq></Where>"

But I get this error One or more field types are not installed properly. Go to the list settings page to delete these fields.

 string docname = "Disabled Service";  
        StringBuilder sb = new StringBuilder();  
        sb.Append("<Where><Eq><FieldRef Name='Name' /><Value Type='Text'>"+docname+"</Value></Eq></Where>");  
        SPQuery spq = new SPQuery();  
        spq.Query = sb.ToString();  
        spq.RowLimit = 1;  
SPList list = web.Lists["Shared Documents"];  
                    DataTable dt = list.GetItems(spq).GetDataTable();  

Kindly help..

  • 1
    got it with "FileLeafRef" Thanks – sanju May 6 '12 at 17:26

The internal name of Name is FileLeafRef so your query should be:

"<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>" + docname + "</Value></Eq></Where>"

If you don't like building the query by hand then a couple of good tools are:
- U2U CAML Query Builder which gives you an UI for building the query.
- CAML.NET which is a library for safely building CAML queries

  • And there's also the Stramit CAML Viewer, spcamlviewer.codeplex.com – Eric Alexander May 7 '12 at 12:44
  • 2
    I'd be curious to know how you find a list of the correct names for fields to use in CAML? Title is "Title" but Name is actually "FileLeafRef"? What gives? – Ray Nov 22 '12 at 23:00
  • Hey Ray, see my answer below on how to get the internal name. – Shai Petel Feb 7 '17 at 16:57

I posted this as a comment but perhaps it is a part of the answer: You need to use the field internal name in your query, not the display name.

The easiest ways to find internal name of columns: 1. If you see the field in list settings, click it. the internal name will be in the query string of the settings page. 2. if you see the field in the list view, sort or filter by it. Again the internal name will be in the query string.

If these fail, in SP2013 you can use the REST API: http://[your site]/_api/web/lists/getByTitle('[list name]')/Fields?$select=Title,InternalName This will get you a list of all fields in that list with their title and internal name.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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