Subject: Reading an attachment without detaching it [It Worked!]
Thanks to Tom Kuczek and Andrew Chung.
The only complication is that because DXL uses Base64 encryption, you need to decode the FILEDATA with the Base64 Lotusscript library that you can find here:
http://www.nsftools.com/tips/NotesTips.htm
[The same page also has a really useful script library for parsing CSV files with XML and another one for just reading CSV. These were no good for me, but might be what you’re looking for]
Obviously the below code is a bit ugly and you–the person looking to use this code–are going to have to do things so that you take care of multiple attachments, attachments in a different format, work with the right kind of attachment, and you’ll probably want some error checking. But we can succesfully read an attachment without detaching it:
Sub Initialize
Dim s As New notessession, db As NotesDatabase, dc As NotesDocumentCollection, d As notesdocument
Dim Stream As NotesStream, export As NotesDXLExporter
Dim x As Integer , st As String, Start As Double, Finish As Double, fd As String
Set db=s.CurrentDatabase
Set dc=db.UnprocessedDocuments
For x=1 To dc.count
Set d=dc.GetNthDocument(x)
If Ucase(d.form(0))="MEMO" Then
'Initalize the stream and DXL Exporters
Set stream=s.createstream
Set export=s.CreateDXLExporter
'Convert the document to DXL
Call export.setInput(d)
Call export.setOutput(stream)
Call export.process
'Process the export into a string file (as long as its less than 2GB)
st=stream.ReadText
'Find the tags and read what’s between them
Start=Instr(1,st,"<filedata>")
Finish=Instr(1,st,"</filedata>")
fd=Mid(st,Start +10, Finish-Start-11)
'Decode from Base 64
fd=decodeBase64(fd)
'fd is your resulting data. Do with it what you will.
End If
Next
End Sub