File Open and Save dialog poping up while opening PDF

Discussion in 'ASP .Net' started by Satya, Jan 22, 2006.

  1. Satya

    Satya Guest

    I am trying to display a PDF file (which I am being passed from a web
    service as a binary stream) in a browser, but I am being prompted to
    save the file instead. I don't want the user to be prompted; I just
    want the PDF to be displayed. Here is the code:

    Byte binaryData;

    binarydata = GetDataHere();
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(binaryData);
    Response.End()

    Note: I am using window.open()(java script) to open the PDF in new
    window.

    I'm using ASP.NET.

    Thanks in advance.

    Satya.
     
    Satya, Jan 22, 2006
    #1
    1. Advertising

  2. > I am trying to display a PDF file (which I am being passed from a web
    > service as a binary stream) in a browser, but I am being prompted to
    > save the file instead. I don't want the user to be prompted; I just
    > want the PDF to be displayed.


    Try adding before Response.BinaryWrite(...) the line

    Response.AddHeader("Content-Disposition", "inline");

    to tell the browser to show the document inline. Note however that the
    problem *could* actually be on the client side, as Adobe Reader
    sometimes refuses to show a PDF inline, even when the
    content-disposition is set to 'inline'.
     
    Paul Henderson, Jan 23, 2006
    #2
    1. Advertising

  3. > Try adding before Response.BinaryWrite(...) the line

    Ya better write bit by bit

    string _filePath = "..."

    Response.Clear();
    Response.AddHeader("Content-Disposition", "inline");
    Response.ContentType = "application/pdf";
    Response.Buffer = false;
    FileStream _fileStream = null;
    byte[] _buffer = new byte[1024];
    long _byteCount;
    try
    {
    _fileStream = File.OpenRead(_filePath);
    while ((_byteCount =
    _fileStream.Read(_buffer, 0, _buffer.Length)) > 0)
    {
    if(Response.IsClientConnected)
    {
    Response.OutputStream.Write(
    _buffer, 0, _buffer.Length);
    Response.Flush();
    }
    else
    {
    return;
    }
    }
    }
    catch(Exception _ex)
    {
    throw _ex;
    }
    finally
    {
    _fileStream.Close();
    }

    --Daniel
    http://staff.newtelligence.com/danielf/




    -----Original Message-----
    From: Paul Henderson [mailto:p]
    Posted At: Monday, January 23, 2006 12:36 PM
    Posted To: microsoft.public.dotnet.framework.aspnet
    Conversation: File Open and Save dialog poping up while opening PDF
    Subject: Re: File Open and Save dialog poping up while opening PDF

    > I am trying to display a PDF file (which I am being passed from a web
    > service as a binary stream) in a browser, but I am being prompted to
    > save the file instead. I don't want the user to be prompted; I just
    > want the PDF to be displayed.


    Try adding before Response.BinaryWrite(...) the line

    Response.AddHeader("Content-Disposition", "inline");

    to tell the browser to show the document inline. Note however that the
    problem *could* actually be on the client side, as Adobe Reader
    sometimes refuses to show a PDF inline, even when the
    content-disposition is set to 'inline'.
     
    Daniel Fisher\(lennybacon\), Jan 23, 2006
    #3
  4. Satya

    Satya Guest

    Hi Paul,

    Thanks for your quick response and I tried the way you suggested but
    still it displaying "File Download" window with following information.

    " Some files can harm your computer .If the file Information below
    looks suspecious ,or you don't fully trust the source,do not open or
    save this file

    File Name : ViewBill.aspx

    File Type : Adobe Acrobat Control For Activex

    >From : localhost


    Would you like to open or save it your computer ? then Open
    ,Save,Cancel and More Info buttons follows.

    Note : Always Ask Before opening this type of file "check box " kept
    checked and it's in disabled in state.

    Hope it would give more info on the issue which I am experiencing .

    Thanks in advance.
    Satya.





    Paul Henderson wrote:
    > > I am trying to display a PDF file (which I am being passed from a web
    > > service as a binary stream) in a browser, but I am being prompted to
    > > save the file instead. I don't want the user to be prompted; I just
    > > want the PDF to be displayed.

    >
    > Try adding before Response.BinaryWrite(...) the line
    >
    > Response.AddHeader("Content-Disposition", "inline");
    >
    > to tell the browser to show the document inline. Note however that the
    > problem *could* actually be on the client side, as Adobe Reader
    > sometimes refuses to show a PDF inline, even when the
    > content-disposition is set to 'inline'.
     
    Satya, Jan 23, 2006
    #4
  5. Satya

    Satya Guest

    Hi All,

    Thank you very much for your help . It worked out for me for following
    code.


    Response.ClearHeaders();
    Response.ClearContent();
    Response.ContentType = "application/pdf";
    Response.AddHeader( "Content-Length", documentData.Length.ToString(
    CultureInfo.CurrentCulture ) );
    Response.AddHeader("Content-Disposition", "inline");
    Response.BinaryWrite( documentData );
    Response.End();

    Thanks again,
    Satya
     
    Satya, Jan 23, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmljYXJkbyBWaWRlaXJh?=

    Poping up a window AND redirecting the page thtat triggered the po

    =?Utf-8?B?UmljYXJkbyBWaWRlaXJh?=, Dec 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    523
    Bruce Barker
    Dec 16, 2005
  2. Jayyde
    Replies:
    0
    Views:
    416
    Jayyde
    Apr 27, 2006
  3. BusyBoy
    Replies:
    2
    Views:
    615
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 31, 2006
  4. Gouse
    Replies:
    2
    Views:
    350
    Kenny McCormack
    Dec 4, 2006
  5. RAJ
    Replies:
    2
    Views:
    181
    Thomas 'PointedEars' Lahn
    Mar 4, 2008
Loading...

Share This Page