上传新附件时更换附件 [英] Replace attachment when uploading a new attachment

查看:185
本文介绍了上传新附件时更换附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的形式和身体领域。当用户上传附件时,我想删除已经在文档的正文字段中的任何附件。我怎样才能在我的保存按钮做到这一点。



我已经试图设置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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆