Writing InfoPath attachments to disk?

K

kb at donovanhill

Hi Clay,

Thanks for your reply, the code example link that you gave is for C# and I
do not have Visual Studio .NET, only VS for Apps which runs with InfoPath
2007.

Will the C# encoder class that you have work with VB.net? could I just
reference it & use it?

Not sure how to make this work??

Thanks
 
S

S.Y.M. Wong-A-Ton

You can try the method described in this blog post:
http://chrissyblanco.blogspot.com/2006/07/infopath-2007-file-attachment-control.html

The translation to VB.NET would look something like the following, where
base64encodedstring is the base64 encoded string for the attachment:

Dim attachmentNodeBytes() As Byte =
Convert.FromBase64String(base64encodedstring)
Dim fnLength As Integer = attachmentNodeBytes(20) * 2
Dim fnBytes() As Byte
ReDim fnBytes(fnLength)

Dim i As Integer
For i = 0 To fnLength
fnBytes(i) = attachmentNodeBytes(24 + i)
Next

Dim charFileName As Char() = UnicodeEncoding.Unicode.GetChars(fnBytes)
Dim fileName As String = New String(charFileName)
fileName = fileName.Substring(0, fileName.Length - 1)

Dim fileContents() As Byte
ReDim fileContents(attachmentNodeBytes.Length - (24 + fnLength))

For i = 0 To fileContents.Length - 2
fileContents(i) = attachmentNodeBytes(24 + fnLength + i)
Next

Dim fs As FileStream = New FileStream("C:\" & fileName, FileMode.Create)
fs.Write(fileContents, 0, fileContents.Length)
fs.Close()
 
S

S.Y.M. Wong-A-Ton

I cannot take credit for the original code; only for the VB.NET translation.
:) I'm glad it worked without much modification, since I don't usually write
much VB code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top