Extracting a word document attatchment from an IBM notes database

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.

Answers


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

Need Your Help

Could anyone help me find this page?

java oracle reference sun

This following link is broken since Sun is acquired by Oracle. Does anyone know what this page is about and where I can find it? Thanks!

ExtJS Grid storing Cell State automagically

javascript gridview extjs

I am porting quite a huge piece of software to an ExtJS Grid. Lots of data (and I mean lots of data) is loaded on-demand into spans that are placed inside grid's cells.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.