I am developing a Java Application which will connect to an IBM notes database and extract the attachment (which will be a word document) from a given database entry. The word document then needs to be saved to the local disk. I have read through similar situations on here but I cant seem to get any further than confirming there is an embedded file within that document, I cant seem to access it. The code I have so far is:
import java.util.Enumeration;
import java.util.Vector;
import lotus.domino.*;
import lotus.domino.cso.RichTextItem;
public class notesRetrieval extends NotesThread
{
public void runNotes()
{
try
{
Session s = NotesFactory.createSessionWithFullAccess("testpassword");
Database db = s.getDatabase("Server1", "dev/test.nsf", false);
View materialview = db.getView("MaterialNumberLU");
Document doc = materialview.getDocumentByKey("3005");
System.out.print(doc.hasEmbedded());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
My hasEmbedded test statement returns true so I know there is an attatchment. If it is of any benefit, the word document on this particular notes entry is named "C4-P0007-BRS.doc". I have had play about with getAttachment(), getEmbeddedObjects(), and getFirstItem() but no avail. Any help much appreciated.
Thanks.
Attachments usually are embedded in Richtext- items (most of the time). In memos the name of this item is "Body". Try the methods of Richtextitem to get the attachment. Here is an example from the designer help:
RichTextItem body = (RichTextItem)doc.getFirstItem("Body");
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());
}
}
There is another possibility to extract embedded objects directly from the document, but therefor you need the name of the attachment. You can get all Attachmentnames using the "Evaluate"- statement:
Vector attachmentNames = session.evaluate("@AttachmentNames", doc);
Enumeration e = attachmentNames.elements();
while (e.hasMoreElements()) {
String attachmentName = e.nextElement();
EmbeddedObject eo = doc.getAttachment( attachmentName );
if (eo.getType() == EmbeddedObject.EMBED_ATTACHMENT) {
eo.extractFile("c:\\extracts\\" + eo.getSource());
}
}