File Open and Save dialog poping up while opening PDF

S

Satya

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

Paul Henderson

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'.
 
D

Daniel Fisher\(lennybacon\)

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[email protected]]
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'.
 
S

Satya

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

Satya

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top