problem with pdfs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott McFadden

    #1

    problem with pdfs

    My aspx page code reads some custom values from the HTTP headers and then
    writes a given pdf to the output stream based upon the header values.
    Unforunately, my code causes IE to pop up an Open / Save dialog instead of
    invoking the Adobe plugin and displaying the pdf inside of I.E. Here is my
    code (file points to a valid pdf and mimetype is set to 'application/pdf')

    private void RenderFile(File Info file, string mimeType){

    this.Context.Re sponse.ContentT ype = mimeType;

    Debug.WriteLine (this.Context.R esponse.Content Type);

    this.Context.Re sponse.AddHeade r("Content-Length",
    file.Length.ToS tring());

    byte[] buffer = new byte[1024];
    int bytesRead = -1;

    FileStream fs = new FileStream(file .FullName, FileMode.Open,
    FileAccess.Read );
    Debug.WriteLine (fs.Length);

    Stream output = this.Context.Re sponse.OutputSt ream;

    int i = 0;
    while ( (bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0 ){

    output.Write(bu ffer, 0, bytesRead);
    }

    output.Close();
    }

    Watched the HTTP traffic through a tunnel and noticed that ASP.NET is
    tacking on a content-type of utf-8 on the response (even though my code set
    it to application/pdf).

    HTTP request
    GET /webtier/PcFileRetriever .aspx?queryStri ngParams omitted for brevity
    HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
    application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
    */*
    Accept-Language: en-us
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
    1.1.4322)
    Host: localhost:81
    Connection: Keep-Alive
    Cookie: ASP.NET_Session Id=dqnbdy45x0pl ax344a1drb55

    HTTP response
    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Wed, 16 Jul 2003 19:41:41 GMT
    X-Powered-By: ASP.NET
    X-AspNet-Version: 1.1.4322
    Cache-Control: private
    Content-Type: application/pdf; charset=utf-8
    Content-Length: 12850530

    Anyone know how to properly stream the pdf file so the IE Adobe browser
    plugin displays it instead of prompting the user to save? thanks

    scott


Working...