Programmatically Extracting Attachments From InfoPath Forms (Including Their Names!)

I have an expense entry solution for a client that leverages InfoPath and workflow.  At one point during the approval process, I need to generate an email that has all of that good InfoPath data as well as the attachments themselves so that (sigh) someone can take that data and manually re-key it into an Oracle database application.

It’s not very difficult to get at or parse the InfoPath form.  I didn’t know how to handle the attachments, however.  After an hour or two of poking around the Internets (an eternity!) I found this article: http://support.microsoft.com/kb/892730

It provide some handy code to extract the attachment from a node in the form.  (You still need to find the node and all that, but that’s just XML parsing).

I know that the attachment is base64-encoded and I originally went down the path of just extracting the the base64 data, decoding it and saving it.  However, I quickly realized I didn’t know how to get the file name itself until I found the aforementioned article.

I had actually found that quite early, but I was put off by its split personality. On the one hand, the article *says* it’s good for InfoPath 2007.  Yet, the code and instructions are all about Visual Studio 2003 and references to InfoPath 2003.

Bottom line, the code that article provided is working well for me (so far).  I can get my InfoPath form, I can parse it, I can find and decode the attachment and I know its name.  What more can one ask of one’s life?

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Technorati Tags: ,,

If you’re worried that your SharePoint environment may be a tad unhealthy, let me help you fix that with a health check.

Leave a Reply

Your email address will not be published. Required fields are marked *