Getting the contents from an attachment into another document

How can I extract an attachment's content/data (not the attachment file) stored in a rich text field to another rich text field? The attachment can be a MSWord or an RTF or just about any word processor document.
I assume what you want to do is take an attachment, get the contents of the attached file, and then put those contents elsewhere in the document or in another document.

That's easier said than done, but it IS doable. I don't have space in this response to give you a lot of code examples, but there are several in the Domino Developer's help and on notes.net (LDD). There's two basic ways of doing this, I'll call INTERNAL and EXTERNAL:

First, no matter which method we use to get the contents of the attached file, we will have to detatch it to the local hard drive, so use the NotesEmbeddedObject class in LotusScript to cycle through the files and save them to a place on the hard drive.

In this scenario, we use the built-in Notes Import routine to import the detatched file, either into the current document or another document. Just call the Import routine from the NotesUIDocument class, making sure the system caret is in the rich text field you want the data to go. You will need to know the type of file and filter you want to use, and all of those are listed in the Domino Designer documentation.

This scenario is a little more complex, but potentially has better results: In this scenario, you take the detatched file and open the appropriate application (Excel, Word, WordPro, WordPerfect, 123, etc), then, using OLE Automation, tell the host application to open the file, and then either embed the OLE object from the application into your rich text field (hard to do programmatically) or copy and paste the contents (which is nice and clean, but may give weird results, depending on the application).

Personally, I use the INTERNAL method most of the time, unless the import filter for the appropriate application just sucks or doesn't perform the import correctly (or at all). In that case, I go through the pain of using the EXTERNAL method.

Hope this helps!


Dig Deeper on Domino Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...