This is definitely an expert question. Please let me know if I need to post this to a different discussion group and which one that would be. Thanks.
Does anyone know of a rock-solid approach to extracting attachments from Notes using the COM API? Maybe the answer is to NOT use the COM API? We have tried the following:
1)
a) The following approach intermittently has a null EmbeddedObject. The biggest problem with this approach is that I have no way to match the externalFileNames (attachment name shown in viewer) with the internal names (pName required by NotesDocument.GetAttachmen
t()).
· Get the internal attachment names from the lotus script @AttachmentName
· Iterate and call the NotesDocument.GetAttachmen
t(internal
Attachment
Name) to get a Domino.NotesEmbeddedObject
· Check the type of NotesEmbeddedObject to ensure it is a Domino.EMBED_TYPE.EMBED_AT
TACHMENT
· Then call EmbeddedObject.ExtractFile
(externalF
ileName);
b) This approach has not been stable. The Navigator intermittently blows up; running the same test again may or may not work (cant be attributed to a certain item)
· Get the body: Domino.NotesItem bodyItem = _dominoNotesDocument.GetFi
rstItem("B
ody");
· Check to ensure body is not null and is Domino.IT_TYPE.RICHTEXT
· Create a NotesRichTextItem: _dominoNotesDocument.Creat
eRichTextI
tem(TEMP_I
TEM_NAME)
· Append the body to the NotesRichTextItem: rti.AppendRTItem((Domino.N
otesRichTe
xtItem)bod
yItem)
· Save the Document: _dominoNotesDocument.Save(
true, false, false);
· Create a Navigator: Domino.NotesRichTextNaviga
tor navigator = rti.CreateNavigator()
· if(navigator.FindFirstElem
ent(Domino
.RT_ELEM.R
TELEM_TYPE
_FILEATTAC
HMENT))
· do
· {
· Domino.NotesEmbeddedObject
embeddedObj = navigator.GetElement()
· embeddedObj.ExtractFile(ex
ternalFile
Name);
· }
· while(navigator.FindNextEl
ement(Domi
no.RT_ELEM
.RTELEM_TY
PE_FILEATT
ACHMENT, 1));
c) This approach blows up intermittently when attempting to iterate the NoteRichTextItem.EmbeddedO
bject array
· Get the body: Domino.NotesItem bodyItem = _dominoNotesDocument.GetFi
rstItem("B
ody");
· Check to ensure body is not null and is Domino.IT_TYPE.RICHTEXT
· Create a NotesRichTextItem: _dominoNotesDocument.Creat
eRichTextI
tem(TEMP_I
TEM_NAME)
· Append the body to the NotesRichTextItem: rti.AppendRTItem((Domino.N
otesRichTe
xtItem)bod
yItem)
· Save the Document: _dominoNotesDocument.Save(
true, false, false);
· object[] embeddedObjects = (object[])rti.EmbeddedObje
cts;
· //check null for embeddedObjects
· foreach(Domino.NotesEmbedd
edObject embeddedObj in (System.Array)rti.Embedded
Objects)
· {
· if (embeddedObj.type == Domino.EMBED_TYPE.EMBED_AT
TACHMENT)
· {
· embeddedObj.ExtractFile(ex
ternalFile
Name);
· }
2) How can we best match up the Attachment internal names with the external names (that display in the viewer)? I can get the internal names from the @AttachmentNames lotus script call. Ex. _dominoNotesDocument.Paren
tDatabase.
Parent.Eva
luate("@At
tachmentNa
mes", _dominoNotesDocument);. But I need to extract the attachment to disk with the external name.
a) I have exported DXL for documents and looked for the attachmentref attribute. This is the only way I have found to get the mapping between internal and external attachment names. Unfortuneately, this is extremely slow and doesnt work for all documents (occaissionally throws exception on certain documents.
Thanks in advance for any feedback!