views:

306

answers:

1

Hi all,

I'm trying to (HTTP) upload a binary file programmatically from within VBA. I intend to put an ASPX page on the server to accept the file and certain additional parameters.

I know there are lots of nice ways to do that (e.g. use web service instead of aspx), but my constraint is that it must run in VBA (in an excel file), and that I cannot install any additional components on the client.

So I guess I'll use WinHTTP, and I've found several examples to post form data, but not to post a binary file. I probably need to base64 the file contents?

So my questions are:

  • Do I need to do the encoding manually or can I make WinHTTP do that?
  • Is there a better utility to use than WinHTTP? (Remember I don't want to install any additional software, it must be shipped with WinXP Pro, Office 2007 or a .NET framework, e.g.)
  • Is there a better way to go, e.g. using ASP.NET web services?

Thx, chiccodoro

+1  A: 

You may use base64 but typically writing binary is easier.

The hurdle you have to leap is constructing a valid multi-par/form POST. This is completely possible using WinHTTP, although I have not done it in years and am not tooled to provide sample code, it is not trivial.

You can reference the following articles for examples of how to do this with C# HttpWebRequest. The WinHTTP api is a bit different of course but the salient points to take away from the articles is the structure of the POST body.

Typically I provide sample code, but as I said, I do not have any stone-age tools set up right now ;-).

HTH

Sky Sanders
Yeah, life as a Neanderthal is hard :-) Thank you for the links, your post on "C# File Upload with form fields, cookies and headers" looks indeed very interesting.
chiccodoro