简体   繁体   中英

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>";

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM