Send Binary Data from ASP

Introduction

One of the more common tasks that we've performed is to send a existing document to the browser. For our client base, the most common document types include Adobe Acrobat (.pdf), Microsoft Word (.doc) and PKZip (.zip). Innately, it is not hard to get these files to the client. Simply using a Response.Redirect to the path for the document works. However, if the documents are kept in a location other than in the hierarchy underneath the web root, there are security considerations that need to be addressed. I don't know about you, but I'd rather look for alternates rather than knowingly expose my site to security holes. As well, if you client has associated the type of the downloaded file with an application on their computer, the document will be automatically opened. In many cases, I would rather have the user save the document in their field system.

Fortunately, we discovered a relatively straightforward option that was open to us. With just a few lines of code, we can not only push binary data directly from ASP, but also force the user to save the document onto their hard drive.

You might also like...

Comments

About the author

Bruce Johnson Canada

I am the owner of a small application development consulting company that specialized in the design and implementation of Internet-based applications. While there are others who can make a web ...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.” - Dan Kaminsky