A Simple Download


The advantages of FileUpEE downloading include:

  • The files to download do not have to be in a browsable location on the server.

  • The path to the file only exists in the server-side code, which helps protect sensitive information from end-users.

  • FileUpEE can download from file server to web server to client (a 3-tier download).

  • FileUpEE can download from a directory or a database.

  • FileUpEE allows you to limit the bandwidth used for downloads per connection and per server.
    
Important!
The behavior of a download is extremely browser-dependent. To ensure that your application works as desired, test it on different browser platforms. Alternatively, use a client-side control such SoftArtisans XFileEE to handle your downloads.

The following ASP and ASP.NET samples demonstrate downloading a single file from web server to client. Note that the download scripts do not contain HTML or Response.Write statements. In a download, the response should include only the downloaded file and its response headers. HTML and Response.Write lines will corrupt the downloaded file.



FileUpEE provides two techniques for downloading files from web server to client: AddDownloadFile/WriteToResponse and TransferFile. The samples above use the AddDownloadFile/WriteToResponse to download the file sample.doc from FileUpEE's doc-samples\samples directory.


Downloading with AddDownloadFile and WriteToResponse

The following VBScript lines download a file using the FileUpEE method AddDownloadFile and the FileEE method WriteToResponse:

To ensure that the download is not corrupted by extraneous characters in the response:

  1. Do not include Response.Write statements in the download script.

  2. Do not include HTML in the download script.

  3. Before calling WriteToResponse, call Response.Clear to erase any buffered HTML output.

  4. In ASP, after calling WriteToResponse, call Response.End. In ASP.NET, after calling WriteToResponse, call Response.Close.

The AddDownloadFile method sets content-type and content-disposition response headers for the file to download. When using the AddDownloadFile/WriteToResponse download method, do not set these response headers in script.

Top


Downloading with TransferFile

To download a file using the FileUpEE method TransferFile:

  1. The TransferFile method does not set response headers for the download. To let the browser know how to handle a download, set the content-type and content-disposition response headers:

    Response.ContentType = "application/msword"
    Response.AddHeader "content-disposition", "attachment;filename=""docdownload.doc"""


  2. Call TransferFile to download the file from the web server to the client:

    strPathToDownloadFile = Server.MapPath("/FileUpEE/Samples/sample.doc")
    oFileUpEE.TransferFile Request, Response, strPathToDownloadFile

To ensure that the download is not corrupted by extraneous characters in the response:

  1. Do not include Response.Write statements in the download script.

  2. Do not include HTML in the download script.

  3. Before setting the response headers, call Response.Clear to erase any buffered HTML output.

  4. In ASP, after calling TransferFile, call Response.End. In ASP.NET, after calling TransferFile, call Response.Close.

Avoid Errors by Using Typelibs

In ASP, Typelibs provide quick and convenient access to constants associated with a particular object. The script in this example includes FileUpEE's TypeLib because the script uses constants (e.g, saWebServer). The UUID attribute specifies FileUpEE's unique identifier.

<!--METADATA TYPE="TypeLib" UUID="{6B16F98B-015D-417C-9753-74C0404EBC37}" -->

Top

Copyright © 2010 SoftArtisans, Inc. All rights reserved.