0

I am trying to search for an item in a SharePoint list using SPQuery, but even though the file is there, the result is null.

The code is the following:

var query = new SPQuery();
query.Query = "<Where><Contains><FieldRef Name='Title' /><Value Type='Text'>" + documentTitle + "</Value></Contains></Where>";

SPListItemCollection listItems = web.Lists["ListName"].GetItems(query);

documentTitle is the name of an existing document, and "ListName" is the name of the list in which the item is.

The item is in the list, but the query returns 0 results.

Can anyone help me with this?

Mimi
  • 41
  • 2
  • 7

2 Answers2

2

Check the Following Code.. this is working for me..

var query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name="LinkFilename" /><Value Type="Computed">"+documentTitle+"</Value></Eq></Where>";
SPListItemCollection listItems = web.Lists["ListName"].GetItems(query);
Rony SP
  • 2,618
  • 15
  • 16
0

Here is a class I wrote for making SPQuery writing easier. Perhaps it can help.

https://gist.github.com/4672176

Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75