SharePoint 2010 offers you the ListViewByQuery control for displaying a list view according to a specified query. While I was trying to do so I got an error saying that “One or more field types are not installed properly. Go to the list settings page to delete these fields.” which was strange since I was querying a simple task list with no custom fields.

Problem description

You can see the error I described in the picture below:

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

The code which produced the error was the following:

MyCustomView = new ListViewByQuery();
MyCustomView.List = currentWeb.Lists["Tasks"];
SPQuery query = new SPQuery(MyCustomView.List.DefaultView);
query.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='Due' />";
query.Query = "<Where><Leq><FieldRef Name='Due' />" +
    "<Value Type='DateTime'>" +
    SPUtility.CreateISO8601DateTimeFromSystemDateTime(filterDate.SelectedDate) +
    "</Value></Leq></Where>";
MyCustomView.Query = query;

As you can see in line 4 and 5 I used a FieldRef Name='Due' which has to be FieldRef Name='DueDate'.

Solution

So here is the working code:

MyCustomView = new ListViewByQuery();
MyCustomView.List = currentWeb.Lists["Tasks"];
SPQuery query = new SPQuery(MyCustomView.List.DefaultView);
query.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='DueDate' />";
query.Query = "<Where><Leq><FieldRef Name='DueDate' />" +
    "<Value Type='DateTime'>" +
    SPUtility.CreateISO8601DateTimeFromSystemDateTime(filterDate.SelectedDate) +
    "</Value></Leq></Where>";
MyCustomView.Query = query;

The code above works with SharePoint 2010 Beta.

Comments

1/8/2010 6:31:43 AM #

Not great to see the exception messages are still just as meaningless in SP2010!

Alex Angas Australia Reply

1/9/2010 5:39:13 PM #

Yes that's right...

Btw: Subscribed to your blog, really interesting!

Andreas Switzerland Reply

Add comment





  Country flag
 

biuquote
Loading