473,748 Members | 9,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Conten tType = "applicatio n/pdf";
Response.Binary Write(binaryDat a);
Response.End()

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

I'm using ASP.NET.

Thanks in advance.

Satya.

Jan 22 '06 #1
4 5627
> 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.Binary Write(...) the line

Response.AddHea der("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.Binary Write(...) the line

Ya better write bit by bit

string _filePath = "..."

Response.Clear( );
Response.AddHea der("Content-Disposition", "inline");
Response.Conten tType = "applicatio n/pdf";
Response.Buffer = false;
FileStream _fileStream = null;
byte[] _buffer = new byte[1024];
long _byteCount;
try
{
_fileStream = File.OpenRead(_ filePath);
while ((_byteCount =
_fileStream.Rea d(_buffer, 0, _buffer.Length) ) > 0)
{
if(Response.IsC lientConnected)
{
Response.Output Stream.Write(
_buffer, 0, _buffer.Length) ;
Response.Flush( );
}
else
{
return;
}
}
}
catch(Exception _ex)
{
throw _ex;
}
finally
{
_fileStream.Clo se();
}

--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.publi c.dotnet.framew ork.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.Binary Write(...) the line

Response.AddHea der("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.Binary Write(...) the line

Response.AddHea der("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.ClearH eaders();
Response.ClearC ontent();
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der( "Content-Length", documentData.Le ngth.ToString(
CultureInfo.Cur rentCulture ) );
Response.AddHea der("Content-Disposition", "inline");
Response.Binary Write( 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
12565
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 code to access file1.exe using virtual folder. <@ Language=JavaScript %>
2
1760
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
3197
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 been unable to determine a method of forcing the dialog box to open in the centre of the screen (or any other position on the screen). How can l control the position on the screen in which the dialog box opens ? Any help would be greatly...
2
2351
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. Mainly cause my boss wanted the Open File Dialog's OK button to read 'Import', for all intensive purposes. Open\Save dialogs where constructed purely from the Win32 API as you cannot inherit these classes from the framework. Problem I am recounting...
0
2978
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 entered. When this button is pressed and extract is prduced and IE's standard Open/Save dialog should popup so they can navigate to the directory to save the extract in, or if they want, they can choose to open and view the extract without saving it. ...
6
2698
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 the excel document. When I click save I can save the excel document or when I click open it directly opens in excel. This works fine for all but one machine. On one machine however the dialog prompts to open or save the excel document (e.g....
0
2508
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 dialog box.Waiting for replies... My code for opening the file: Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AppendHeader("content-disposition", ...
0
3791
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 file Open, Save or Cancel button, if I click open after that it is opening the document. But my query is it should not display this dialog box, once I click the link it should open the document automatically using HttpServletResponse. Can any one help...
0
1141
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 i.e. Desktop, Program Files and Windows from the hierarchy. For other folders list i can always use database per user. Using file permission i can restrict the access but my whole problem lies in hiding the folders ? I am using VS.net 2005 (C#)...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.