Search code examples
javalotus-noteslotus-domino

Get .txt file from Lotus Notes document using Java


I created the notes doument using java code and then created the rich text field as follow

           doc = db.createDocument();
            doc.replaceItemValue("FROMMAIL", "[email protected]");
            doc.replaceItemValue("SENDTO", "[email protected]");
            doc.replaceItemValue("SUBJECT", "NotesSlrWriter");
            DateTime s2 = sess.createDateTime(new Date());
            System.out.println("Setting date to: "
                    + s2.toJavaDate().toLocaleString());
            doc.replaceItemValue("POSTEDDATE", s2);

            RichTextItem t = doc.createRichTextItem("Attachements");
            t.appendText("Here is the Attachment");
            t.addNewLine(2);
            t.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null,
                    "c:\\test\\test.txt", "testtxt");
            doc.save();

So i know from using doc.getItemValue(arg0) values i can get the values of the other field in my java code.

But i don't know how i can get test.txt in a Attachment field of Notes Document into my java class


Solution

  • In case if you do not know the file name, you can walk through all attachments in RichTextItem.

    Below is example that scan 1 richtextitem and export all files in folder.

    RichTextItem body = doc.getFirstItem("Attachements");
    Vector v = body.getEmbeddedObjects();
    Enumeration e = v.elements();
    while (e.hasMoreElements()) {
       EmbeddedObject eo = (EmbeddedObject)e.nextElement();
    
       if (eo.getType() == EmbeddedObject.EMBED_ATTACHMENT) {
             System.out.println("\t" + eo.getName());
             eo.extractFile("c:\\extracts\\" + eo.getSource());
             eo.remove();
       }
    }
    

    There is another solution, that may help you:

    EmbeddedObject eo = doc.getAttachment("testtxt");
    System.out.println(eo.getName());
    eo.extractFile("c:\\extracts\\" + eo.getSource());