Reputation: 109
I have a Document Library on SharePoint which hosts documents of different types and i have a custom search web part which is supposed to search the library and display documents based on search type along with other search criteria.Problem is i cant search for the document type, My CAML query is as follows:
SPWeb web = site.OpenWeb();
SPList document = web.Lists["Training Docs"];
SPListItemCollection objItemcoll;
SPQuery objQuery = new SPQuery();
objQuery.Query = "<Where><Contains><FieldRef Name=\"Name\"/>
<Value Type=\"Text\"></Value>doc</Contains></Where>";
objItemcoll = document.GetItems(objQuery);
if (objItemcoll.Count > 0)
{
foreach (SPListItem item in objItemcoll)
{
//Binding To Grid;
}
}
}
Im guessing the fault is with value type=" " . Any help would be appreciated.
Upvotes: 0
Views: 1631
Reputation: 10345
Try:
<Where><Contains><FieldRef Name='FileLeafRef' /><Value Type='Text'>doc</Value></Contains></Where>
I created this query using the U2U CAML Query Builder. You might want to try it. It is the resource for creating CAML query strings for SPQuery objects.
Upvotes: 1