473,382 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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. 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
4 5598
> 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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Venkat | last post by:
Hi, I have an file1.exe file stored at some physical location say C:\Test\file1.exe. I created a virtual folder say MyFolder pointing to my physical folder(C:\Test\). I wrote this piece of...
2
by: Ronnie Jensen | last post by:
Hi There. Unfortunally I forgot how to create an open/save dialog (Access 2000), from which I can retrieve the the filename to open/save. Can anyone tell me how.. Thanks in advance Ronnie
1
by: ASH | last post by:
Hello all, I'm using the "API: Call Windows File Open/Save Dialog Box" to source the name of a file to open. The Dialog Box when called opens in the top left hand corner of the screen. I have...
2
by: SpotNet | last post by:
Hi Newsgroup, I have constructed highly customisable common dialog classes\objects. Decided to extend the Open\Save dialog options with the ability to change the text on all the controls. ...
0
by: Dune | last post by:
Hi there, I have an aspx page that allows users to enter several parameters using drop downs and text boxes. The users then press a button that produces an extract based on the parameters they...
6
by: Michael Groeger | last post by:
Hi, I have an aspx page which generates an excel document and transfers it to the browser as attachment. Normally, once the document is transferred the open save dialog prompts to open or save...
0
by: de4ever | last post by:
I have used open/save dialog box inside update panel in asp.net.but it is not working because of the code line Response.WriteFile(path);.Can i use any thing else for opening a file through open/save...
0
by: aarthiraaj | last post by:
In my user screen I have view link, if I click this link it will go to servlet and open one word document. It is opening properly, but while opening the attachment it generate one dialog box like...
0
by: miztaken | last post by:
Hi Everyone, Is it possible to customize.net's default File Open/Save Dialog Box to display only selected folders in PC according to user's privilege. I want to totally hide the Special Folders...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.