Description of "download.aspx"

This script is used by all the download links. It takes two parameters, either as QueryString variables or Form variables, which give it the file name and indicate whether it should send the file inline or as an attachment.

The files are all in the same directory and the physical path is found by using the Server.MapPath. It could have been hard coded instead.

The file extension is found by using Path.GetExtension and this is used to set the Response.ContentType property. This tells the browser what type of file will follow. The System.IO namespace must be imported to use the Path class.

The file is streamed by calling the FileName property with the full path and file name passed as a parameter.

<%@ Page language="vb" debug="true" %>
<%@ Import NameSpace = "csNetDownload" %>
<%@ Import NameSpace = "System.IO" %>
<%
Response.Expires = 0
If Request("File") = "" Then
  Response.Redirect("http://www.chestysoft.co.uk/aspnet/netdownload/demo.htm")
End If
Dim Download As New DownloadClass
Dim FilePath = Server.MapPath("../../notshared") & "\"
Dim FileName = FilePath & Request("File")
Dim Extension = Ucase(Path.GetExtension(FileName))

Dim MIME As string
Select Case Extension
  Case ".ZIP" : MIME = "application/x-zip-compressed"
  Case ".PDF" : MIME = "application/pdf"
  Case ".GIF" : MIME = "image/gif"
  Case ".JPG" : MIME = "image/jpeg"
  Case ".HTM" : MIME = "text/html"
  Case ".DOC" : MIME = "application/msword"
  Case ".TXT" : MIME = "text/plain"
End Select

Response.ContentType = MIME
If Request("Attachment") Then
  Download.Attachment = true
Else
  Download.Attachment = false
End If
Download.StreamFile(FileName)
%>

If any user verification was required, such as checking a password, it would be done before streaming the file. If any logs or database records needed updating they could be done at the end.

Click Here to return to the download page.