SPQuery not returning expected results
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>";开发者_JAVA百科
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?
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);
Here is a class I wrote for making SPQuery writing easier. Perhaps it can help.
https://gist.github.com/4672176
精彩评论