sharepoint-2013 - 如何在文档集中搜索文件?
问题描述
我正在尝试编写 CAML 查询以在特定文档集中按文件名查找特定文件。
这是我正在处理的查询:
<查询> <哪里> <方程式> <FieldRef 名称='FileLeafRef' /> <Value Type='File'>TestFile.txt</Value> </方程式> </哪里> </查询> <查询选项> <文件夹>https://acme.com/sites/mysite/MyDocLib/MyDocSetName</文件夹> </查询选项>
由于在名为 MyDocSetName 的文档集中有一个名为 TestFile.txt 的文件,我希望得到一个结果,但没有任何结果。我究竟做错了什么?
解决方案
基于此演示的示例测试脚本。
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js", function() {
$.getScript(scriptbase + "SP.js", function() {
$.getScript(scriptbase + "SP.DocumentManagement.js", createDocumentSet);
});
});
});
var docSetFiles;
function createDocumentSet() {
//Get the client context,web and library object.
clientContext = new SP.ClientContext.get_current();
oWeb = clientContext.get_web();
var oList = oWeb.get_lists().getByTitle("DocSet");
clientContext.load(oList);
//Get the root folder of the library
oLibraryFolder = oList.get_rootFolder();
var documentSetFolder = "/DocSet/test1";
//Get the document set files using CAML query
var camlQuery = SP.CamlQuery.createAllItemsQuery();
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>test2.docx</Value></Eq></Where></Query></View>");
camlQuery.set_folderServerRelativeUrl(documentSetFolder);
docSetFiles = oList.getItems(camlQuery);
//Load the client context and execute the batch
clientContext.load(docSetFiles, 'Include(File)');
clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
}
function QuerySuccess() {
//Loop through the document set files and get the display name
var docSetFilesEnumerator = docSetFiles.getEnumerator();
while (docSetFilesEnumerator.moveNext()) {
var oDoc = docSetFilesEnumerator.get_current().get_file();
console.log("Document Name : " + oDoc.get_name());
}
}
function QueryFailure() {
console.log('Request failed - ' + args.get_message());
}
</script>
推荐阅读
- dart - VSCode 中的表情符号
- javascript - 如何使用 webpack 包含整个 polyfills 文件夹?
- excel - 在选定单元格旁边插入文本 - Excel VBA
- angular - 角 2+ | 嵌入 booking.com 地图小部件
- r - 通过在 R 中获取他们每月的最后一个日期来转换周到月
- android - 如何判断设备在 Google Play 商店中不兼容的原因
- r - 使用 Tidyverse 函数将 tibble 列中的多个唯一值重新编码为单个新值
- javascript - 我应该在反应组件或 redux 操作中获取数据吗?
- python - 如何在没有逆和画线的情况下从矩阵映射轮廓?
- javascript - 根据包含来自另一个数组的所有值的数组属性过滤对象数组