如何在List项目上添加任何附件时保存文件而不单击“保存”按钮 [英] How to save file when add any attachment on List item without click on Save button
问题描述
我已使用
文章,当我附加文件时,它会在页面中添加文件,但只有在单击保存按钮后才会将附件保存在列表中。
现在我想将文件添加到List项目用户点击附加按钮,因此无需点击保存按钮,我该怎么做?
MS_21212
您需要使用CSOM或REST API向项目添加附件。
这是一个关于如何使用REST API / _api / lists / GetByTitle('" + listName +"')/ items(" + itemId +")添加项目附件的演示。 )/ AttachmentFiles / add(FileName ='"
+ file.name +"')
1.使用Designer打开编辑表单,在< asp:Content contentplaceholderid =" PlaceHolderMain" runat =" server"> tag:
注意:将列表名称更改为您的。
< script src =" https://code.jquery .com / jquery-1.10.2.js">< / script>
< script type =" text / javascript">
var context;
var web;
var Url;
var listItemEntity;
//将列表名称更改为你的
var listName =" cl01"
(document).ready(function(){
SP.SOD.executeFunc('sp .js','SP.ClientContext',FunctionReady);
ItemSubmit();
});
函数FunctionReady(){
context = new SP.ClientContext.get_current();
web = context.get_web();
context.load(网页);
context.executeQueryAsync(onRequestSuccess,onRequestFailure);
}
函数onRequestSuccess(){
Url = web.get_url();
GetListItemEntity(Url);
}
function onRequestFailure(sender,args){
alert(" Error Occured:" + args.get_message());
}
//用于获取列表项实体类型
函数GetListItemEntity(webUrl){
var queryUrl = webUrl +" / _ api / lists / getbytitle('" + listName +"')?
select = ListItemEntityTypeFullName" ;;
I have added attachment field in SharePoint 2013 custom edit form (in custom list) using article , when I attach file it adds files in the page but only after click of save button its save the attachment in List.
Now I want to add files to List item when user clicks on attach button only and hence there will be no need to click on save button, how I can do this?
MS_21212
Hi,
You need to add attachments to items using CSOM or REST API.
Here is a demo about how to add attachments to an item using REST API /_api/lists/GetByTitle('" + listName + "')/items(" + itemId + ")/AttachmentFiles/add(FileName='" + file.name + "')
1. Open the edit form using Designer, add the following code under <asp:Content contentplaceholderid="PlaceHolderMain" runat="server"> tag:
Note: change list name to yours.
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript"> var context; var web; var Url; var listItemEntity; // change list name to yours var listName="cl01"
(document).ready(function () { SP.SOD.executeFunc('sp.js', 'SP.ClientContext', FunctionReady); ItemSubmit(); }); function FunctionReady() { context = new SP.ClientContext.get_current(); web = context.get_web(); context.load(web); context.executeQueryAsync(onRequestSuccess, onRequestFailure); } function onRequestSuccess() { Url = web.get_url(); GetListItemEntity(Url); } function onRequestFailure(sender, args) { alert("Error Occured:" + args.get_message()); } //Used to get the List Item Entity Type function GetListItemEntity(webUrl) { var queryUrl = webUrl + "/_api/lists/getbytitle('"+listName+"')?
select=ListItemEntityTypeFullName";
这篇关于如何在List项目上添加任何附件时保存文件而不单击“保存”按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!