Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Writing InfoPath attachments to disk?

650 views
Skip to first unread message

kb at donovanhill

unread,
Nov 13, 2007, 2:08:01 AM11/13/07
to

Using InfoPath 2007, I would like to write an attached file to my local
drive using VB.net within the form. As the attachments are encoded as base64,
has anyone decoded and removed the header info using VB.net?

One example I have seen uses C#
http://www.cubido.at/Blog/tabid/176/EntryID/40/Default.aspx
I cannot get this to work.

Any help would be appreciated.

--
kb

Clay Fox

unread,
Nov 13, 2007, 3:21:04 PM11/13/07
to
I have done this using this code.
http://support.microsoft.com/kb/892730

--
Thanks

Clay Fox

Qdabra Software
http://www.qdabra.com

InfoPathDev.Com
The Largest InfoPath Forum in the World
http://www.infopathdev.com

kb at donovanhill

unread,
Nov 15, 2007, 10:16:02 PM11/15/07
to
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
--
kb

S.Y.M. Wong-A-Ton

unread,
Nov 16, 2007, 4:13:02 AM11/16/07
to
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.Y.M. Wong-A-Ton

kb at donovanhill

unread,
Nov 19, 2007, 12:29:01 AM11/19/07
to
Your code worked, fanastic job!!

THANKS VERY MUCH!
--
kb

S.Y.M. Wong-A-Ton

unread,
Nov 19, 2007, 7:31:01 PM11/19/07
to
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.

res...@gmail.com

unread,
Aug 22, 2016, 3:37:55 AM8/22/16
to
Hi All,

Is there a way to do this in java? I am using base64decoder which works well for pdf and word attachments. However excel attachment does not get extracted.
Thanks
0 new messages