Now that we have access to the byte array of data from within ASP, it is a staightforward process to use it.
<%
Response.Buffer = True
Response.Clear
Response.AddHeader "content-disposition", "attachment; filename="
& FileName
Response.ContentType = "application/pdf"
vStream = oUtility.ReadBinaryFile(Server.MapPath(PathName))
Response.BinaryWrite(vStream)
Set oUtility = Nothing
Response.End
%>
Since we are adding headers to the Reponse object, it is important that nothing
be written to the Response object before we use the AddHeader method. If not,
then an ASP error will inform you of the foolishness of your code. By setting
the Buffer property to True and clearing the Response, we satisfy this requirement.
If these was a large ASP page, then I would put Response.Buffer at or near the
top.
The AddHeader method is used to specify the method that the browser will use
to handle the incoming file. As wel have already mentioned,the default is to
launch the application on the client's system that is associated with the file
type of the download. With the AddHeader method, we tell the browser to prompt
to save the file locally using "FileName" as the default. The ContentType
property is to provide information about the file type so that the browser can
process it correctly. The default content type of "text/html" doesn't
allow the BinaryWrite method to be used. Different content types would be used
for Word documents (application/ms-word), JPGs (image/jpeg) or Zip files (application/zip).
Comments