Convert Decoded Byte string to attachment

Hi,

I have decoded the (attachment data in byte format) string which I retrieved from DXL and was able to pass it on to an existing stream which will create a word document for me.

Now, what is happening is that the decoded string is showing inline in the word document.

Instead, I want to show the data as an attachment and then append it to the word document which I am creating using stream.

If this is not possible, then I am thinking of extracting the files manually to the file system and then append to the word file using office automation.

Please advice on how this can be accomplished.

–Phani

PS : As the agent is running on server, I want to avoid automation which will cause lot of problems if not used properly. Wanted to know whether the same could be done using streams.

The basic thing which I wanted to accomplish is to

  1. Export the current document (already in html format with all the data) to word (I have completed this task)

  2. Embed all attachments present in the document to the word document created above.

Subject: Convert Decoded Byte string to attachment

What do you mean by “the decoded string is showing inline in the word document”. I would like to help but I do not really understand what you are trying to do.

/Mikkel Heisterberg

Visit my Notes/Domino blog @ http://lekkimworld.com

for posts on Notes/Domino and how to use Java in Notes/Domino…

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