Caml Query返回null

时间:2015-08-19 05:33:30

标签: sharepoint-2013 web-parts caml sharepointdocumentlibrary

我试图使用CAML Query从文档库中检索文档,但此查询返回null。请帮忙解决这个问题。

SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)oWebsite.Lists["SampleDocument"];

SPQuery query = new SPQuery();
query.Query = string.Format("<Where><Eq><FieldRef Name='Author' /><Value Type='Text'>Name</Value></Eq></Where>");
SPListItemCollection collListItems = oDocumentLibrary.GetItems(query);

DataTable dt = collListItems.GetDataTable();

1 个答案:

答案 0 :(得分:0)

如果查询返回的确切结果,您可以在Caml中查看Caml Designer查询。

尝试Camlex使用Nuget

添加CamlexNET
using CamlexNET;
var caml = Camlex.Query().Where(x => ((string)x["Author"] == "Value").ToString();
var query = new SPQuery
{
     Query = caml,
     RowLimit = 5000
};

SPList list = web.Lists["Document"];
SPListItemCollection items = list.GetItems(query);

foreach (SPListItem itm in items)
{
   //var id = Convert.ToString(itm["ID"]);
}