10

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..

0

2 Answers 2

21

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

3
  • And there's also the Stramit CAML Viewer, spcamlviewer.codeplex.com Commented May 7, 2012 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? Commented Nov 22, 2012 at 23:00
  • Hey Ray, see my answer below on how to get the internal name. Commented Feb 7, 2017 at 16:57
2

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.