Extracting and reattaching attachments

Extracting and reattaching attachments

My problem is like the one in this Ask the Expert question, but a bit different. In many documents I have more than one attachment and I don't necessarily know the names in advance. My project is to extract these attachments, save them and reattach them in another field. Can you help me solve my problem?

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

You can find out the name of the attachments using standard functions of Domino. Using @Functions, you can use the function @AttachmentNames, which will give you a list of attachment names for the attachments in the current document.

I have added a LotusScript example below, which will guide you in the proper direction. Using the EmbeddedObjects property of the Notes document or Rich Text item, you get a list of embedded objects in your document (i.e., attachments). Then, by using the GetAttachment method, you get a handle to an attachment, which is stored in the class type of NotesEmbeddedObject. This class has properties such as Remove, ExtractFile etc.

Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim object As NotesEmbeddedObject
Set db = New NotesDatabase
( "server", "db" )
Set view = db.GetView( "viewname" )
Set doc = view.GetLastDocument
Forall o In doc.EmbeddedObjects
  Set object = doc.GetAttachment( o )
Call notesEmbeddedObject.ExtractFile
( "path to save file to" )
Call notesEmbeddedObject.Remove
End Forall

This was first published in October 2003