How to Transfer Large File from MS Word Add-In (VBA) to Web Server?

Posted by Ian Robinson on Stack Overflow See other posts from Stack Overflow or by Ian Robinson
Published on 2009-04-29T16:53:51Z Indexed on 2010/03/19 16:11 UTC
Read the original article Hit count: 216

Filed under:
|
|
|
|

Overview

I have a Microsoft Word Add-In, written in VBA (Visual Basic for Applications), that compresses a document and all of it's related contents (embedded media) into a zip archive. After creating the zip archive it then turns the file into a byte array and posts it to an ASMX web service. This mostly works.

Issues

The main issue I have is transferring large files to the web site. I can successfully upload a file that is around 40MB, but not one that is 140MB (timeout/general failure).

A secondary issue is that building the byte array in the VBScript Word Add-In can fail by running out of memory on the client machine if the zip archive is too large.

Potential Solutions

I am considering the following options and am looking for feedback on either option or any other suggestions.

Option One

Opening a file stream on the client (MS Word VBA) and reading one "chunk" at a time and transmitting to ASMX web service which assembles the "chunks" into a file on the server.

This has the benefit of not adding any additional dependencies or components to the application, I would only be modifying existing functionality. (Fewer dependencies is better as this solution should work in a variety of server environments and be relatively easy to set up.)

Question:

  • Are there examples of doing this or any recommended techniques (either on the client in VBA or in the web service in C#/VB.NET)?

Option Two

I understand WCF may provide a solution to the issue of transferring large files by "chunking" or streaming data. However, I am not very familiar with WCF, and am not sure what exactly it is capable of or if I can communicate with a WCF service from VBA. This has the downside of adding another dependency (.NET 3.0). But if using WCF is definitely a better solution I may not mind taking that dependency.

Questions:

  • Does WCF reliably support large file transfers of this nature? If so, what does this involve? Any resources or examples?
  • Are you able to call a WCF service from VBA? Any examples?

© Stack Overflow or respective owner

Related posts about vba

Related posts about asmx