How to Extract All Attachments in a Document Held $File

This post follows on from my post yesterday:http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/2ea002efd41cc94e8525737d004ff0fa?OpenDocument

I am looking at an alterantive to GetAttachment(filename) of getting a handle on all attachments stored in a document - all in $FILE, not a RTF - and detach them to the file-system. The key thing is getting the handle on each attachment to be able to call the ExtractFile method?

Thanks

Subject: How to Extract All Attachments in a Document Held $File

You should be able to use NotesEmbeddedObject.

See example here: http://www-12.lotus.com/ldd/doc/domino_notes/6.5.1/help65_designer.nsf/f4b82fbb75e942a6852566ac0037f284/982c6ee5284050bb85256e00004a918b?OpenDocument

Or do you have attachments that are not in a RichTextField?

Subject: RE: How to Extract All Attachments in a Document Held $File

That is the problem the attachments are all stored in the $FILE. They don’t exist in a Rich Text Field.

Subject: RE: How to Extract All Attachments in a Document Held $File

You can still use NotesEmbeddedObject.

Instead of the NotesRichTextItem.EmbeddedObjects property, you can use NotesDocument.EmbeddedObjects property, which gets you the attachments even if they are not in a rich text field.

Subject: RE: How to Extract All Attachments in a Document Held $File

Doesn’t seem to work. This is what I was working with but copy/paste staright from Designer Help:If doc.HasEmbedded Then

Forall o In doc.EmbeddedObjects

  Messagebox( o.Name )

End Forall

Else

This gives Type Mismatch on the Forall. Seems to be a common problem and I cannto find the solution…

Subject: RE: How to Extract All Attachments in a Document Held $File

EmbededObjects property of NotesDocument does not give you File Attachments according to Notes help. So it is working as intended.

Amir Kashani

Subject: RE: How to Extract All Attachments in a Document Held $File

So, how do we detach all the files then?

Problem is that in some filenames we have Unicode characters which are not standard therefore the GetAttachment(filename) does not work for such files.

Somehow I therefore need to work out a means of extracting the file in $File without getting a handle on it using GetAttachment!

Subject: RE: How to Extract All Attachments in a Document Held $File

Wrong. You might want to read the Help entry a bit more closely – the EmbeddedObjects property of the NotesDocument includes attachments that are not associated with a rich text field. (We regularly use it in WQS agents to move attachments from the document to a particular rich text field.)

Subject: RE: How to Extract All Attachments in a Document Held $File

This is what I thought. It is really strange. I am finding it virtually impossible to extract the attachments that the GetAttachment method fails to return.

Is this as simple as Notes being unable to support the encoding/character set?

Subject: RE: How to Extract All Attachments in a Document Held $File

I believe that this is a case of badly written documentation. I.e., first it says:

“Note Embedded objects and object links are not supported for OS/2, UNIX, and the Macintosh. File attachments are.”

This implies that file attachments are returned by this property.

But then it says.

“Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments, nor OLE/1 objects created in Notes Release 3.”

Strictly as written, this implies that file attachments are not returned. But I believe that the qualification “created in Notes Release 3” really means “created in R3 or later inside rich text fields”, and that despite the positioning of the commas, that qualification was really intended to apply to file attachments in addition to OLE/1 objects. So what it really, really means is that NotesDocument.EmbeddedObjects doesn’t return attachments created inside an RTF, but does return attachments that are “below the line”.

Subject: RE: How to Extract All Attachments in a Document Held $File

Richard, Thank you for the clarification. I do agree that documentation is a bit confusing. So I looked at it again as Stan suggested(though I have looked at this documentation many times before). I also looked at the example at the end of which it states:

“EmbeddedObjects does not return the Ami Pro document because the object was created in Notes Release 3. It does not return castle.bmp because castle.bmp is a file attachment.”

So I wrote a quick code to check on documents submitted via web and I am not getting handle on any attachments below the line. I tested on Windows XP, R7 and R6. It might work work in WQS agents which I did not check. May be someone else can confirm.

Subject: RE: How to Extract All Attachments in a Document Held $File

Are you getting the type mismatch at runtime? Or at compile time?

Subject: RE: How to Extract All Attachments in a Document Held $File

I get error at Runtime

Subject: RE: How to Extract All Attachments in a Document Held $File

That clearly indicates that HasEmbedded is returning true; and I believe that NotesDocument.HasEmbedded and NotesDocument.EmbeddedObjects are consistent with each other, so you should find the attachments in the EmbeddedObjects array, and we just need to work out why the forall isn’t working for you.

But to be honest, I think I’ve tried using forall before with EmbeddedObjects and had the same problem. It seems that all my current code working with EmbeddedObjects avoids using a forall, and looks more like this:

If rtf.hasEmbedded Then

Dim objects As Variant

objects = rtf.EmbeddedObjects

Dim i As Integer

For i = 0 To Ubound(objects) 

    Dim o As NotesEmbeddedObject

    Set o = objects(i)

    If o.Name = "something" Then

         ' do something

    End If

Next

end if

Since I’m sure my preference would have been to use a forall, I think it must be that I faced the same problem you did and since nothing seemed obvious about why it didn’t work, I just switched to a regular for loop.

-rich

Subject: RE: How to Extract All Attachments in a Document Held $File

Thanks Richard, but that assumes that I have an RTF field?

objects = rtf.EmbeddedObjects

All my attachments are in $FILE not RTF fields. This is really to root of my problem…

Interestingly doc.HasEmbedded = True but EmbeddedObjects is NULL.

Subject: RE: How to Extract All Attachments in a Document Held $File

Well, that was just pulled from my code that does use the rtf. The point was just to show the alternative to forall. I expected you to modify it from using rtf to doc accordingly, and I expected it to not throw a type mismatch.

But if doc.HasEmbedded is true, while EmbeddedObjects is coming back as Nothing, then I have no clue.

-rich

Subject: RE: How to Extract All Attachments in a Document Held $File

Hi Lemens,

Could you find solution for it . I have the same problem.

Subject: RE: How to Extract All Attachments in a Document Held $File

Have you tried reading the $FILE items directly?

Subject: RE: How to Extract All Attachments in a Document Held $File

One way of doing this is by Evaluating a Domino formula @AttachmentNames and stepping through the resulting values to extract your file(s).

filenames = Evaluate(“@AttachmentNames”,doc)