Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 67,543 times

Contents

Related Categories

Send Binary Data from ASP - ASP Modifications

LACanadian

ASP Modifications

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).

I am the owner of a small application development consulting company that specialized in the design and implementation of Internet-based applications. While there are others who can make a web site look good, our expertise is in making the site function. This includes infrastructure design, database design and administration, software development and deployment. For the most part, we utilize Microsoft-based languages and tools. And we are skilled enough to have generated two patent applications for our clients.

Comments

  • Posted by ckchan on 12 Feb 2006

    Hi, thanks for the code. i tested it in my ASP site.

    i find however the code works for pdf files of around <80K size. Once the pdf files goes past 80K, the code bombs. All i see in the req...

  • RE:Opening PDF in Windows 2000

    Posted by victormois on 10 Oct 2005

    gjohnson, I can think of two things.
    1. check XP/IE security settings
    2. Reinstall Adobe Reader.

  • Opening PDF in Windows 2000

    Posted by gjohnson on 08 Oct 2005

    I am having the exact same problem except my code works on a Windows XP computer but does not work in Windows 2000. In XP, acrobat opens in my web application and the pdf displays as it should. In 2...

  • pdf content into an array

    Posted by rocko_hunk on 06 Oct 2005

    hi below is the code u sent

    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(tPDF);
    Response.End();

    I know very well that I n...

  • Posted by victormois on 05 Oct 2005

    rocko_hunk, sure it will throw an error on this line: Response.BinaryWrite(tFileName)
    Because, tFileName is a string and you need to pass to Response.BinaryWrite method a binary array with proper PDF...