[英]Output SharePoint Document Library Files to CSV File Using JavaScript
I'm seeking how to output SharePoint Document Library Files to csv file.我正在寻找如何将 output SharePoint 文档库文件转换为 csv 文件。 I found script that get me almost there, but I can't figure out how to update the code to export the information to a csv file instead to the console.log() or to an alert().
我找到了几乎可以让我到达那里的脚本,但我不知道如何更新代码以将信息导出到 csv 文件而不是 console.log() 或 alert()。 Everything I tried breaks the code.
我尝试的一切都会破坏代码。 I review other JavaScript concept that shows the how to add out to CSV but I again the script concept breaks the code I'm trying to modify.
我查看了其他 JavaScript 概念,该概念显示了如何添加到 CSV 但我再次脚本概念破坏了我试图修改的代码。 The script I am using.
我正在使用的脚本。 In addition, the script output the file names.
另外,脚本 output 的文件名。 I like to get help on how I can not only output the file name, but I like to output, modified date, created date, and the link to the file.
我想获得有关如何不仅 output 文件名的帮助,而且我喜欢 output、修改日期、创建日期和文件链接。 I hope this is possible and I appreciate any help in achieving this concept.
我希望这是可能的,我很感激在实现这个概念方面的任何帮助。 Script I'm using follows below.
我正在使用的脚本如下。
jQuery(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("Fact Sheets & Agreements");
clientContext.load(oList);
//Get the root folder of the library
oLibraryFolder = oList.get_rootFolder();
var documentSetFolder = "sites/nbib/ep/Fact%20Sheets/";
//Get the document set files using CAML query
var camlQuery = SP.CamlQuery.createAllItemsQuery();
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();
alert("Document Name : " + oDoc.get_name());
console.log("Document Name : " + oDoc.get_name());
}
}
function QueryFailure() {
console.log('Request failed - ' + args.get_message());
}
Sample test script in chrome. chrome 中的示例测试脚本。
function QuerySuccess() {
//Loop through the document set files and get the display name
var csv = 'Document Name\n';
var docSetFilesEnumerator = docSetFiles.getEnumerator();
while (docSetFilesEnumerator.moveNext()) {
var oDoc = docSetFilesEnumerator.get_current().get_file();
//alert("Document Name : " + oDoc.get_name());
//console.log("Document Name : " + oDoc.get_name());
csv += oDoc.get_name();//+',' if more cloumns
csv += "\n";
}
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
hiddenElement.target = '_blank';
hiddenElement.download = 'DocumentList.csv';
hiddenElement.click();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.