Hi guys

Need some help with an problem thats bugging me..
I have to open a .pdf file at the client side when the user clicks a button..

Opening is not a problem.. I am able to do it using the following code
which is executed when the user clicks on the button

MyFileStream = New FileStream("E:\MyWork\Test\DownloadFiles\Reports\Rpt.pdf", FileMode.Open)
FileSize = MyFileStream.Length
Dim Buffer(CType(FileSize, Integer)) As Byte
MyFileStream.Read(Buffer, 0, CType(MyFileStream.Length, Integer))
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=MyReport.PDF")

The problem is that the user first sees a 'Open/ Save / Cancel' dialog box. Only when the user clicks on 'Open' does the .pdf file get opened.
My client wants it to be opened directly when the button is clicked.
Am at a loss and any help will be appreciated...

Thanks in advance

Also is there any other way to open the file at the client side?

Hi ,
R u seaching for something like this.....

String strPop = "<script language='javascript'>" + Environment.NewLine +
"window.open('E:\MyWork\Test\DownloadFiles\Reports\Rpt.pdf"','Report','height=520,width=730,toolbars=no,scrollbars=yes,resizable=yes');" + Environment.NewLine +
"</script>" + Environment.NewLine;
Page.RegisterStartupScript("Pop", strPop);
Hope this will help u

Member Avatar for Dukane

I think that all depends on the client's browser.


i think the best thing is using javascript to open the pdf

try this:

<INPUT id="btnopen" type="button" value="open report" name="Button1" onclick="location.href='linux1-sample.pdf'">


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.