Reputation: 41
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?
Upvotes: 0
Views: 1498
Reputation: 5435
Here is a class I wrote for making SPQuery writing easier. Perhaps it can help.
https://gist.github.com/4672176
Upvotes: 0
Reputation: 2628
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);
Upvotes: 2