Session session = null;
Database db = null;
View vw = null;
try {
session = NotesFactory.createSession("host" + ":63148", "user", "password");
db = session.getDatabase(null, "database.nsf");
vw = db.getView("someview");
Document doc = vw.getFirstDocument();
RichTextItem body = null;
body = (RichTextItem) doc.getFirstItem("Attachments");
if (body == null) {
body = doc.createRichTextItem("Attachments");
}
File file = new File("c:/work/someattachment.jpg");
String path = file.getAbsolutePath();
// attach to notes
EmbeddedObject eo = body.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "",
path, null);
doc.save(true);
} catch (NotesException ne) {
ne.printStackTrace();
} finally {
if (session != null) {
try {
session.recycle();
} catch (Exception e) {
e.printStackTrace();
}
}
}