0

I have a web part I have developed in Visual Studio. It just goes out to a document library and gets all the items:

SPListItemCollection collListItems = oDocumentLibrary.GetItems();

This works fine. But whenever I try to include a query:

SPQuery qry = new SPQuery();
qry.ViewFields = "<FieldRef Name=\"Name\"/><FieldRef Name=\"Modified\"/><FieldRef Name=\"Url\"/>";
qry.ViewFieldsOnly = true; // Fetch only the data that we need.
qry.ViewAttributes = "Scope=\"Recursive\"";

SPListItemCollection collListItems = oDocumentLibrary.GetItems(qry);

and try to add the web part to a page I get the following error on the page:

Failed to render "Wiki Content" column because of an error in the "multiple lines of text" field type control. Value does not fall within the expected range

  • Do you have any other web part in this page and where is your qry.Query? You should set the Query property also. – Atish Dipongkor - MVP Sep 23 '15 at 16:33
  • No other web part. I tried setting the query property too but the same result. The difference between getting the error and not getting it has to do with using a query: GetItems(qry) vs GetItems() – steveareeno Sep 23 '15 at 17:19
  • does oDocumentLibrary.GetItems(qry); return any items? – Atish Dipongkor - MVP Sep 23 '15 at 17:42
1

The error was due to my ViewFields SPQuery property settings. I must have been using the wrong field names. "Name" is supposed to be "LinkFilename" and "Url" is supposed to be "ServerUrl". I was basing the field names off the SPListItem object model names which are "Name" and "Url". Thanks to Atish for making me check my query results.

  • That's all right! In CAML query, don't forget to user internal name of fields – Atish Dipongkor - MVP Sep 23 '15 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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