上传新附件时更换附件 [英] Replace attachment when uploading a new attachment
问题描述
我已经试图设置fileUpload控件上的固有名称,以始终将文件名更改为相同的名称,但这不会取代该文件,而是它添加一个新的文件,并添加一个新的序列号
< xp:fileUpload id =fileUpload1 value =#{userdoc.Body}filename =profileseUploadname =false>< / xp:fileUpload>
在保存之前,我也尝试过在body字段中循环所有嵌入的附件,然后所有附件删除了,但我的新附件没有添加。
有点晚,但万一有人像我一样Google ...
另外还有一个选项:NotesXSPDocument.getAttachmentList(rtitem)返回文档中的附件列表。每个条目都是
var attList = docFile.getAttachmentList(files); (i = 0; i< attList.size(); i ++){
var att = attList.get(i);
if(att.getState()== 0){// STATE_INDOCUMENT:'old'file:remove it
docFile.removeAttachment(files,att.getName ));
} else if(att.getState()== 1){// STATE_ADDED:这是新文件
//保留
}
}
I have a simple form and body field. when user upload an attachment I want to remove any attachment already in the body field of the document. how can I do this in my save button.
I have tried to set the properites on the fileUpload control to always change the filename to tha same name but this does not replace the file, instead it adds a new file and add a new sequential number to it
<xp:fileUpload id="fileUpload1" value="#{userdoc.Body}" filename="profile" seUploadname="false"></xp:fileUpload>
I have also tried to loop all embedded attachments in body field before before save, and all attachments are then removed, but my new attachment is not added.
A little late, but in case anyone gets here just as I did through Google...
There's also another option: a NotesXSPDocument.getAttachmentList("rtitem") returns a list of attachments in the document. Each entry is of type DominoDocument.AttachmentValueHolder which has a getState() property that returns if a file was already in the document or just added. To remove the file that was already in the document you could add this SSJS code to a save button (assuming "files" is the name of the richtext item holding the files):
var attList = docFile.getAttachmentList("files");
for(var i=0; i<attList.size(); i++) {
var att = attList.get(i);
if (att.getState()==0) { //STATE_INDOCUMENT: this is the 'old' file: remove it
docFile.removeAttachment("files", att.getName() );
} else if (att.getState()==1) { //STATE_ADDED: this is the new file
//leave it
}
}
这篇关于上传新附件时更换附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!