By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,589 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,589 IT Pros & Developers. It's quick & easy.

File Open and Save dialog poping up while opening PDF

P: n/a
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.

Jan 22 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> 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'.

Jan 23 '06 #2

P: n/a
> 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:pa***********@pittville.demon.co.uk]
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'.

Jan 23 '06 #3

P: n/a
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'.


Jan 23 '06 #4

P: n/a
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

Jan 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.