SPQuery returning error "One or more field types are not installed properly. Go to the list

Hi

SPQuery is not working properly, its throwing following exception.

"One or more field types are not installed properly. Go to the list settings page to delete these fields."

Please check the code snippet below:

SPSite spsite =newSPSite("siteurl");

SPWeb site = spsite.OpenWeb();

SPList list = site.Lists["listname"];

SPQuery query =newSPQuery();

query.Query ="<Where><Eq><FieldRef Name='ServiceLevel'/><Value Type='String'>345</Value></Eq></Where>";

SPListItemCollection items = list.GetItems(query);

foreach (SPListItem iteminitems) //here its throwing exception.

{

Console.WriteLine(SPEncode.HtmlEncode(item.Xml) +"<BR>");

}

[1936 byte] By [sujazach] at [2008-1-1]
# 1

Hi,

The problem is with the field name in the SPQuery. CAML expects Internal Name not the display name. Here is a blog from where i got this answer. http://thorprojects.com/blog/archive/2007/02/23/643.aspx

- Subbu

SubbuZ at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 2

Change the Value Type from String to Text and try again. It should work and if it still gives you the error, then use the internal name of the field. To get th internal name of the field, open the "New" form and click "View Source" from context menu (right click any where in the "New" form page to open the context menu). You will see the fields along with their internal names near the end of the source file.

Hope this helps

SSA

MOSS MVP

--

SSAhmed at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 3

Hi,

I have same problem.

It works when I query 'Title' field, but not other fields. I have checked internal field name same as external field name.

But it still return the error: "One or more field types are not installed properly. Go to the list settings page to delete these fields."

Thanks in advance for your help

Ray

rlinxu at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 4

Are you sure the field name is same as internal name? Title field is always same, no matter external or internal but other fields, especially the ones with the spaces between them, are different. Best way (for debugging) is to remove all fields and add 2-3 fields at a time and then run your code but to avoid wasting time, i would suggest check the internal names of all the fields that you are using in your code. I am sure using the correct internal names will solve your problem. I also saw a utility other day that shows you the internal names of the fields. Anyway, you can also check the internal names yourself (hint view source of the form).

SSAhmed at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...

SharePoint Products and Technologies

Site Classified