|
asp.net upload faq
» Intro
» How to
» Quickstart
» Advanced
» Troubleshoot
resources
» Download Source Code
» ASP.NET Upload Control
search site
|
Quickstart: Download from the filesystemThis quickstart will walk you through building a handler to support downloads from the server filesystem. » PrerequisitesAn ASP.NET site with a page you want to use to handle downloads. This example is downloadable as an ASP.NET 2.0 web site solution, but the code and settings described below will work exactly the same in any version of ASP.NET (v1.0-v3.5). For ASP.NET 1.0, see the workaround in the Stream file download how to entry. » Creating a download handlerFirst, you need to create a handler resource that will perform the actual download to the client. You could use an aspx, but since its just a file download the whole page lifecycle isn't needed. In this case, it's better to use an ashx, which is basicaly a barebones endpoint. This avoids the unneccessary overhead of the aspx. To create the download handler
After adding the handler, the handler source code should look like this:
» Adding download codeNow that the handler shell exists, we need to add code to actually perform the download. Information about the important sections can be found in the how to: » Set the Content-Type for a download» Set a file name for a download and show download dialog» Stream file downloadTo add code to the download handler
Now when this handler gets hit for a valid file the user gets a download box – with file name:
© 2009 Krystalware
|