Subject: RE: Convert Decoded Byte string to attachment
Sorry for the confusions. The following code should help you out to understand what I am trying to do -
Sub Initialize
'This agent creates a word document
On Error Goto ErrorHandler 'Error Handler
Dim s As New NotesSession
Dim db As notesdatabase
Dim c As NotesDocument
Dim stream As NotesStream
Dim HTMLcontent As String, HTMLhead As String ,HTMLbody As String
Dim rtiHTMLhead As NotesRichTextItem, rtiHTMLbody As NotesRichTextItem
Set db = s.CurrentDatabase
Set c = s.DocumentContext
Set stream = s.CreateStream
Set rtiHTMLhead = c.GetFirstItem(“HTMLhead”)
Set rtiHTMLbody = c.GetFirstItem(“HTMLbody”)
HTMLhead= rtiHTMLhead.GetUnformattedText()
HTMLbody= rtiHTMLbody.GetUnformattedText()
'Building HTML string which then would be converted to word using stream below
HTMLcontent = || _
-
HTMLhead _
-
|| _
-
HTMLbody _
-
||
'Sets the download to use word
Print |Content-Type:application/msword; charset=“UTF-8”|
'Triggers the save/open prompt instead of embedding the word in the browser.
Print |Content-Disposition:Attachment; filename=“Report.doc”|
Call stream.WriteText(HTMLcontent, EOL_NONE)
stream.Position = 0 'Setting the starting position of stream to 0
Do
Print stream.ReadText(0, EOL_CRLF)
Loop Until stream.IsEOS
Exit Sub
ErrorHandler:
Print ||
Exit Sub
End Sub
So, as you can see, I am creating a word document using stream by reading the HTML content which I got from the current document.
The current document may also contain attachments which I want to embed in word document. So, I implemented the following code -
Dim exporter As NotesDXLExporter
Dim attstream As NotesStream
Dim filedata As Variant
Dim docstream As Variant
Set attstream = s.CreateStream
Set exporter = s.CreateDXLExporter
Call exporter.setInput(c)
'Set output of the exporter to “attstream” stream object
Call exporter.setOutput(attstream)
Call exporter.process
docstream = “”
attstream.Position = 0
docstream = attstream.ReadText
'Read what is inbetween
Dim start As Long,finish As Long, fd As String
Start=Instr(1,docstream,“”)
Finish=Instr(1,docstream,“”)
fd=Trim(Mid(docstream,Start +10, Finish-Start-11))
'Function written by Julian Robichaux, maintained
by him on the http://www.nsftools.com website.
fd=decodeBase64(fd)
Dim arr(0) As String
arr(0) = fd
I am getting the decoded data and I am trying to insert the data (arr(0)) like the following in HTMLContent string (created above)
HTMLcontent = || _
-
HTMLhead _
-
|| _
-
HTMLbody _
-
arr(0) _
-
||
When the word document is outputted I am seeing the Decoded string appended to the word file. What I am expecting is to see the file attached.
I know I am doing something wrong. Could you guide me of any other ways of appending the attachments to the stream which is creating a word document.
Thanks,
–Phani