是否可以在SharePoint站点中使用CSOM查询多个列表?

时间:2017-03-20 21:44:08

标签: c# .net sharepoint

我的具体问题是我获得了以下格式的网址:

https://sharepoint.business.com/sites/SHAREPOINT/_layouts/15/DocIdRedir.aspx?ID=SHAREPOINT-823645913-12

没有办法直接使用该类型的链接检索文档数据,而无需先将其转换为服务器绝对文件路径,例如:

https://sharepoint.business.com/sites/SHAREPOINT/Documents/TestDocument.pdf

从给定的URL,我没有指示我将在哪个列表中找到实际文档,所以目前我唯一的解决方案是在循环中查询所有列表,这看起来非常糟糕且效率低下。

使用唯一的文档ID,是否有一种简单/优雅的方式来查询整个SharePoint网站中的所有数据?

当前伪代码:

ListCollection lists = SharePoint.Client.Web.Lists;

ctx.Load(lists);

ctx.ExecuteQuery();

Loop at all lists {
    Use CAML query to grab absolute file path from Document ID.
}

Retrieve individual file that I actually want, using GetFileByServerRelativeUrl API method.

提前致谢,如果我需要澄清任何内容,请告诉我。

1 个答案:

答案 0 :(得分:1)

是的,使用Search API搜索整个网站或网站集。

using Microsoft.SharePoint.Client.Search;
using Microsoft.SharePoint.Client.Search.Query;

string documentId = "SHAREPOINT-823645913-12";
KeywordQuery kQry = new KeywordQuery(clientContext);
kQry.QueryText = "DocId:" + documentId;
SearchExecutor searchExec = new SearchExecutor(clientContext);
ClientReuslt<ResultTableCollection> results = searchExec.ExecuteQuery(kQry);
clientContext.ExecuteQuery();

foreach(var result in results.Value[0].ResultRows)
{
    //do stuff with result which contains the URL property for the document
    //along with any other crawled attribtues
}