Ask the Expert

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 (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!


This was first published in September 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: