How do I get all the attachments from a .nsf(lotus notes) file using java

后端 未结 4 702
耶瑟儿~
耶瑟儿~ 2021-01-01 05:50

Steps followed :

Took a back of my lotus notes as sample.nsf

And then tried to read the attachments from the sample.nsf

Cod

4条回答
  •  暖寄归人
    2021-01-01 06:07

    No need to use evaluate, look up the extractFile in the Lotus Designer Help

    From the Lotus help:

    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();
        }
      }
    }
    

提交回复
热议问题