Вывод файлов библиотеки документов SharePoint в файл CSV с использованием JavaScript - PullRequest
0 голосов
/ 21 октября 2019

Я ищу способ вывода файлов библиотеки документов SharePoint в файл CSV. Я нашел сценарий, который почти дошел до меня, но я не могу понять, как обновить код, чтобы экспортировать информацию в CSV-файл, вместо этого в console.log () или в alert (). Все, что я пробовал, нарушает код. Я рассматриваю другую концепцию JavaScript, которая показывает, как добавить в CSV, но я снова использую концепцию сценария, которая нарушает код, который я пытаюсь изменить. Сценарий, который я использую. Кроме того, скрипт выводит имена файлов. Мне нравится получать справку о том, как я могу не только выводить имя файла, но я люблю выводить, дату изменения, дату создания и ссылку на файл. Я надеюсь, что это возможно, и я ценю любую помощь в достижении этой концепции. Сценарий, который я использую, следует ниже.

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());


} 

1 Ответ

1 голос
/ 21 октября 2019

Пример тестового скрипта в 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();
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...