本文介绍了如何使用Java从.nsf(莲花笔记)文件中获取所有附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已执行的步骤:
把我的莲花笔记的背面作为sample.nsf
Took a back of my lotus notes as sample.nsf
然后尝试从sample.nsf中读取附件
And then tried to read the attachments from the sample.nsf
代码段:
Database db = session.getDatabase("","C:\\Projects\\NotesToJava\\sample.nsf");
DocumentCollection dc = db.getAllDocuments();
Document doc = dc.getFirstDocument();
while (doc != null) {
RichTextItem body = (RichTextItem) doc.getFirstItem("Body");
if (body.getEmbeddedObject("Request.xlsx") != null)
System.out.println("Found BPM_Dev_Access_Request.xlsx in " + doc.getItemValueString("Subject"));
doc = dc.getNextDocument();
}
推荐答案
无需使用evaluate
,请在Lotus Designer帮助中查找extractFile
No need to use evaluate
, look up the extractFile
in the Lotus Designer Help
从Lotus帮助中:
import lotus.domino.*;
import java.util.Vector;
import java.util.Enumeration;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Database db = agentContext.getCurrentDatabase();
DocumentCollection dc = db.getAllDocuments();
Document doc = dc.getFirstDocument();
boolean saveFlag = false;
while (doc != null) {
RichTextItem body =
(RichTextItem)doc.getFirstItem("Body");
System.out.println(doc.getItemValueString("Subject"));
Vector v = body.getEmbeddedObjects();
Enumeration e = v.elements();
while (e.hasMoreElements()) {
EmbeddedObject eo = (EmbeddedObject)e.nextElement();
if (eo.getType() == EmbeddedObject.EMBED_ATTACHMENT) {
eo.extractFile("c:\\extracts\\" + eo.getSource());
eo.remove();
saveFlag = true;
}
}
if (saveFlag) {
doc.save(true, true);
saveFlag = false;
}
doc = dc.getNextDocument();
}
} catch(NotesException e) {
System.out.println(e.id + " " + e.text);
e.printStackTrace();
}
}
}
这篇关于如何使用Java从.nsf(莲花笔记)文件中获取所有附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!