注意:这个方法是将附件放到富文本中,然后再将富文本当做存储的介质,进行存取删的操作
取附件方法------------------------------------------
通过Notesdocument.EmabledObjects属性取得
Java代码
- Dim db As NotesDatabase
- Dim view As NotesView
- Dim doc As NotesDocument
- Set db = New NotesDatabase( "SanFrancisco", "hill.nsf" )
- Set view = db.GetView( "All Documents" )
- Set doc = view.GetLastDocument
- If doc.HasEmbedded Then
- Forall o In doc.EmbeddedObjects
- Messagebox( o.Name )
- End Forall
- Else
- Messagebox "No embedded objects found"
- End If
view plaincopy to clipboardprint?
- Dim db As NotesDatabase
- Dim view As NotesView
- Dim doc As NotesDocument
- Set db = New NotesDatabase( "SanFrancisco", "hill.nsf" )
- Set view = db.GetView( "All Documents" )
- Set doc = view.GetLastDocument
- If doc.HasEmbedded Then
- Forall o In doc.EmbeddedObjects
- Messagebox( o.Name )
- End Forall
- Else
- Messagebox "No embedded objects found"
- End If
拆离方法-------------------
可以用NotesEmbeddedObject这个对象的ExtractFile方法
Java代码
- Dim doc As NotesDocument
- Dim rtitem As Variant
- Dim fileCount As Integer
- Const MAX = 100000
- fileCount = 0
- '...set value of doc...
- Set rtitem = doc.GetFirstItem( "Body" )
- If ( rtitem.Type = RICHTEXT ) Then
- Forall o In rtitem.EmbeddedObjects
- If ( o.Type = EMBED_ATTACHMENT ) _
- And ( o.FileSize > MAX ) Then
- fileCount = fileCount + 1
- Call o.ExtractFile _
- ( "c:\reports\newfile" & Cstr(fileCount) )
- Call o.Remove
- Call doc.Save( True, True )
- End If
- End Forall
- End If
view plaincopy to clipboardprint?
- Dim doc As NotesDocument
- Dim rtitem As Variant
- Dim fileCount As Integer
- Const MAX = 100000
- fileCount = 0
- '...set value of doc...
- Set rtitem = doc.GetFirstItem( "Body" )
- If ( rtitem.Type = RICHTEXT ) Then
- Forall o In rtitem.EmbeddedObjects
- If ( o.Type = EMBED_ATTACHMENT ) _
- And ( o.FileSize > MAX ) Then
- fileCount = fileCount + 1
- Call o.ExtractFile _
- ( "c:\reports\newfile" & Cstr(fileCount) )
- Call o.Remove
- Call doc.Save( True, True )
- End If
- End Forall
- End If
再次上传附件方法-------
可使用Notesrichtextitem的EmbedObject方法上传
Java代码
- Dim session As New NotesSession
- Dim db As NotesDatabase
- Dim doc As NotesDocument
- Dim rtitem As NotesRichTextItem
- Dim object As NotesEmbeddedObject
- Set db = session.CurrentDatabase
- Set doc = New NotesDocument( db )
- Set rtitem = New NotesRichTextItem( doc, "Body" )
- Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", "c:\jim.sam")
- //RichTextItem body = null;
- //body =(RichTextItem)doc.getFirstItem("Body");
- //body.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, uploadFilePath, uploadFileName);
- doc.Form = "Main Topic"
- doc.Subject = "Here's Jim's document, as an attachment"
/**
* 上传附件到notes文档
**/
public String uploadAttachsToDoc(String login_user,String attdocunid ,String suploadFilePath,String suploadFileName,Database dbattach){
Document doc=null;
File file=new File(localpath);
if(!file.exists()){
file.mkdirs();
}
try
{
RichTextItem body = null;
if(attdocunid==null || attdocunid.length()==0){
doc =dbattach.createDocument();
doc.replaceItemValue("form","fileAttach_Form");
body = doc.createRichTextItem("Body");
//body.appendText("Here is the attachment:");
//body.addNewLine(2);
//body.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, suploadFilePath, suploadFileName);
Item item=doc.replaceItemValue("Query_String_Decoded","openForm&sysFileAttachName&sysFileAttachRead&sysFileAttachHName");
}else{
doc=dbattach.getDocumentByUNID(attdocunid);
}
if(doc!=null){
doc.replaceItemValue("FCreater",login_user);
if(doc.hasItem("Body")){
body =(RichTextItem)doc.getFirstItem("Body");
}else{
body = doc.createRichTextItem("Body");
Item item=doc.replaceItemValue("Query_String_Decoded","openForm&sysFileAttachName&sysFileAttachRead&sysFileAttachHName");
}
Vector v=body.getEmbeddedObjects();
if(v!=null){
Enumeration e=v.elements();
boolean flag=true;
while(e.hasMoreElements()){
EmbeddedObject eo=(EmbeddedObject)e.nextElement();
if(eo.getName().equals(suploadFileName)){
if(eo.getType()==EmbeddedObject.EMBED_ATTACHMENT){
eo.extractFile(file.getPath()+file.separator+eo.getSource());
//body.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, file.getPath()+ File.separator+ eo.getSource(), eo.getSource());
System.out.println(eo.getSource());
if(eo.getName().toString().equals(suploadFileName)){
flag=false;
break;
}
}
}
}
if(flag){
body.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, suploadFilePath, suploadFileName);
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
try{
if(doc!=null)
doc.save();
} catch(Exception e3) {
e3.printStackTrace();
}
String docUnid=null;
try{
docUnid=doc.getUniversalID();
} catch(Exception e8) {
e8.printStackTrace();
}
doc=null;
//上传成功删除文件
deleteFile(suploadFilePath);
return docUnid;
}
/* 删除单个文件
* @param sPath 被删除文件的文件名
* @return 单个文件删除成功返回true,否则返回false
*/
public boolean deleteFile(String sPath) {
boolean flag = false;
File file = new File(sPath);
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) {
file.delete();
flag = true;
}
return flag;
}