The behavior of a download is heavily browser-dependent. The only way to ensure that your application works as desired is to extensively test on many different browser platforms. Alternatively, you can use a client-side control such as SoftArtisans XFileto handle your downloads. |
FileUp's TransferFile
method downloads a file from server to browser. TransferFile
takes
the parameter FileName
- the path and name of the file to download.
You can set FileName
to either a virtual path or a physical path:
TransferFile with a physical path |
---|
<% FileUp.TransferFile "c:\folder\sample.doc" %>
|
TransferFile with a virtual path |
---|
<% FileUp.TransferFile server.mappath("sample.doc") %>
|
The NTFS permissions on the file to be downloaded must be set to allow "Read" access to the identity under which FileUp is running.
To download from a database, use FileUp's TransferBlob
method.
To let the browser know how to handle a download, you must include three response headers in the download script:
"application/msword"
."inline"
, the file will
open in the browser. Depending on browser security settings, the user may be prompted
with an "open or save" dialog. The user can choose to save to the file system, or
open the file directly in the browser, if the browser supports a plug-in associated
with that file type.
"attachment"
, the browser will open
a dialog that asks whether the user wants to open or save the downloaded file. In
this situation, the user can either save the file to the file system or open the
file in it's native application.
Response buffering is enabled by default in ASP 3.0 and higher. This is not an ideal situation for downloading large files as the entire file will be placed in memory before it is sent to the browser. This may result in memory spikes on the server or the appearance that the browser is hanging, while it waits for the Response from the server.
It is recommended that you disable Response buffering on the page level on those
pages that use FileUp to download files. This can be done as follows:
<% @Language="VBScript" %>
<% Response.Buffer = False %>
Add this line near the top of your ASP page. It must occur before any HTML or Response.Write statements. When you disable Response buffering, remove any instances of Response.Clear or Response.Flush from your code as they will cause your script to fail.
A download script should not include Response.Write statements or any
HTML. If the response includes anything other than the file and response headers,
the downloaded file will be corrupted.
|
The HTTP response's content-disposition header lets the browser know whether to
open the downloaded file in the browser, or it's native application. This header
also tells the browser the name of the downloaded file. If content-disposition is
set to "inline"
- as in the following example - the file will open
in the browser, provided browser security settings allow this type of action.
<
|
A download script should not include Response.Write statements or any
HTML. If the response includes anything other than the file and response headers,
the downloaded file will be corrupted.
|
The HTTP response's content-disposition header lets the browser know whether to
open the downloaded file in the browser, or open the file in the file's native application.
If content-disposition is set to "attachment"
- as in the following
example - the browser will display a dialog that asks the user to open or save the
file. Choosing "open" will result in the file being opened in its native application.
Choosing "save" allows the user to save the file to the file system.
This header also tells the browser the name of the downloaded file.
<%
|