[英]How to get attachment document into form or download it to local from sharepoint List
I have a list in sharepoint 2013 and created an html form and script which will insert data and upload a document into this list.我在 sharepoint 2013 中有一个列表,并创建了一个 html 表单和脚本,它将插入数据并将文档上传到此列表中。 Now for second level, i want to fetch and only view all these saved data which i created.
现在对于第二级,我想获取并只查看我创建的所有这些保存的数据。 I used jsom to fetch all the records
我使用 jsom 来获取所有记录
But problem is with attachment- How to get attachment document into form or download it to local from this list.但问题在于附件 - 如何将附件文档转换为表单或从此列表下载到本地。 Not finding any good resource in google.
在谷歌中找不到任何好的资源。 Can any one please help me?.
谁能帮帮我吗?。
You could use JSOM to get the attachement files.您可以使用 JSOM 来获取附件文件。
Sample script:示例脚本:
<script type="text/javascript" src="/SiteAssets/jquery-3.4.1.js"></script>
<script type="text/javascript">
function getListItemAttachements() {
//replace the list and id dynamically
getAttachements("Test", 1);
}
function getAttachements(listName, itemID) {
var attachmentFiles;
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
var attachmentFolder = web.getFolderByServerRelativeUrl('Lists/' + listName + '/Attachments/' + itemID);
attachmentFiles = attachmentFolder.get_files();
ctx.load(attachmentFiles);
ctx.executeQueryAsync(function () {
for (var j = 0; j < attachmentFiles["$2_1"].length; j++) {
var file = attachmentFiles.itemAt(j);
console.log(file.get_name());
}
}, function (err) {
console.log(err);
});
}
</script>
<input id="Button1" onclick="getListItemAttachements()" type="button" value="button" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.