How can I programmatically add a file attachment to an InfoPath form using VB.Net?

Would anyone know how to add a file from disk to a InfoPath 2007 form as a
file attachment using code? The following link has a c# example but I
can not get this to work.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Clay FoxDirector of Business IntegrationCommented:
You want to have a file automatically attached or you do not want to have the user browse for it?

I have done a seperate attach process to automatically take an email attachment and inject it into a form before.

Give me a bit more details of what you are trying to do.
kbessent1966Author Commented:
Hi Clay,

Thanks for your response, I need to inject a PDF file into the form as an attachment. The PDF file is located on the local PC hard drive. Therefore, the user will not browse for it, the user clicks a button within the form, then the code collects the C:\test.pdf file, encodes to base64, assigns header info etc. The user then can open the PDF from the InfoPath form via a standard attachment control (right click open).

Hope this clears things up.
Clay FoxDirector of Business IntegrationCommented:
I did this exact thing about a year and a half ago. I have the solution and source code.

Why don't you email me from here and we can discuss.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kbessent1966Author Commented:
Hi Clay, I have emailed you directly about obtaining the source code for this problem, when you have chance, could you please email a copy to me at
Thanks Kevin Bessent.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.