Wednesday, November 22, 2006

Resumable file downloads in ASP.NET

The http protocol implements the ACCEPT-RANGES and ETAG response headers to signify the ability to download resources in chunks. There is an interesting article published in MSDN magazine which has some sample code implemented in VB.NET. For the records, similar implementations can be found at:
  1. http://www.thescripts.com/forum/thread334139.html
  2. http://www.devx.com/dotnet/Article/22533/0/page/1

I have made a C# implementation of this code which you can download from http://www.velodoc.com/downloads/061122.blog.zip.

To use this code, you need to:

  1. Create a C# class library named “Memba.FileDownload” or whatever name you deem more appropriate and add the two class files from the archive.
  2. Create a web site and add the following to the system.web/httpHandlers section of the web.config:
    <add type="Memba.FileDownload.DownloadHandler, Memba.FileDownload" validate="false" path="*.zip" verb="*"/>
  3. You also need to make sure the zip extension is mapped to the aspnet_isapi.dll in the IIS management snap-in otherwise your handler will not be called.

To test this code, download a zip file hosted on the web site you have just created. You should be able to stop and resume the download in Internet Explorer or any download manager which supports resumable downloads.

No comments: