lotus 附件的存、 取 、删

注意:这个方法是将附件放到富文本中,然后再将富文本当做存储的介质,进行存取删的操作 
取附件方法------------------------------------------ 
通过Notesdocument.EmabledObjects属性取得 

 

Java代码 

  1. Dim db As NotesDatabase  
  2. Dim view As NotesView  
  3. Dim doc As NotesDocument  
  4. Set db = New NotesDatabase( "SanFrancisco""hill.nsf" )  
  5. Set view = db.GetView( "All Documents" )  
  6. Set doc = view.GetLastDocument  
  7. If doc.HasEmbedded Then  
  8.   Forall o In doc.EmbeddedObjects  
  9.     Messagebox( o.Name )  
  10.   End Forall  
  11. Else  
  12.   Messagebox "No embedded objects found" 
  13. End If 

view plaincopy to clipboardprint?

  1. Dim db As NotesDatabase 
  2. Dim view As NotesView 
  3. Dim doc As NotesDocument 
  4. Set db = New NotesDatabase( "SanFrancisco""hill.nsf" ) 
  5. Set view = db.GetView( "All Documents" ) 
  6. Set doc = view.GetLastDocument 
  7. If doc.HasEmbedded Then 
  8.   Forall o In doc.EmbeddedObjects 
  9.     Messagebox( o.Name ) 
  10.   End Forall 
  11. Else 
  12.   Messagebox "No embedded objects found" 
  13. End If 



拆离方法------------------- 
可以用NotesEmbeddedObject这个对象的ExtractFile方法 

Java代码 

  1. Dim doc As NotesDocument  
  2. Dim rtitem As Variant  
  3. Dim fileCount As Integer  
  4. Const MAX = 100000 
  5. fileCount = 0      
  6. '...set value of doc...  
  7. Set rtitem = doc.GetFirstItem( "Body" )  
  8. If ( rtitem.Type = RICHTEXT ) Then  
  9.   Forall o In rtitem.EmbeddedObjects  
  10.     If ( o.Type = EMBED_ATTACHMENT ) _  
  11.     And ( o.FileSize > MAX ) Then  
  12.       fileCount = fileCount + 1 
  13.       Call o.ExtractFile _  
  14.       ( "c:\reports\newfile" & Cstr(fileCount) )  
  15.       Call o.Remove  
  16.       Call doc.Save( True, True )  
  17.     End If  
  18.   End Forall  
  19. End If 

view plaincopy to clipboardprint?

  1. Dim doc As NotesDocument 
  2. Dim rtitem As Variant 
  3. Dim fileCount As Integer 
  4. Const MAX = 100000 
  5. fileCount = 0     
  6. '...set value of doc... 
  7. Set rtitem = doc.GetFirstItem( "Body" ) 
  8. If ( rtitem.Type = RICHTEXT ) Then 
  9.   Forall o In rtitem.EmbeddedObjects 
  10.     If ( o.Type = EMBED_ATTACHMENT ) _ 
  11.     And ( o.FileSize > MAX ) Then 
  12.       fileCount = fileCount + 1 
  13.       Call o.ExtractFile _ 
  14.       ( "c:\reports\newfile" & Cstr(fileCount) ) 
  15.       Call o.Remove 
  16.       Call doc.Save( True, True ) 
  17.     End If 
  18.   End Forall 
  19. End If 



再次上传附件方法------- 
可使用Notesrichtextitem的EmbedObject方法上传 

Java代码 

  1. Dim session As New NotesSession  
  2. Dim db As NotesDatabase  
  3. Dim doc As NotesDocument  
  4. Dim rtitem As NotesRichTextItem  
  5. Dim object As NotesEmbeddedObject  
  6. Set db = session.CurrentDatabase  
  7. Set doc = New NotesDocument( db )  
  8. Set rtitem = New NotesRichTextItem( doc, "Body" )  
  9. Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, """c:\jim.sam")  
  10. //RichTextItem body = null;
  11. //body =(RichTextItem)doc.getFirstItem("Body");
  12. //body.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, uploadFilePath, uploadFileName);
  13. doc.Form = "Main Topic" 
  14. 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;  
	}  

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值