Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

open new page when download PDF/help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bbulsara23@hotmail.com - 10 Jan 2006 13:15 GMT
Hi, this has been asked so many times before but I cannot get an answer
that works.

So I'm asking again.

I am using .Net 1.1 on a Windows XP Pro.

What I want is for the browser to display a PDF "inline" in the browser
in a "new" window. The PDF comes from a database and I stream it to the
browser. The key points are "inline" and "new window". My code works
but it displays the PDF in the current window.

Here is an example. This code is executed on a button click on the
server. When I remove the comments, the browser displays junk. I would
like it to display my document in a new window. Any ideas on how I can
get this to work?

Thank you
Barry

' Response.BufferOutput = True
' Response.ClearHeaders()
' Response.ClearContent()
' Response.ContentType = "text/plain"
' Response.AddHeader("Content-Type", "text/plain")
' Response.Write("<script
language=""javascript"">window.open()</script>")

Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "inline; filename=cv.pdf")
Response.AddHeader("Content-Type", "application/pdf")
Response.WriteFile(myCV.ToString())
Response.Flush()
Response.Close()
bbulsara23@hotmail.com - 10 Jan 2006 14:20 GMT
Oops, I posted to the wrong group.
I have reposted to microsoft.public.dotnet.aspnet

Barry
Norman Yuan - 10 Jan 2006 14:25 GMT
Server side code is not allowed to open new browser window (otherwise client
computer would be flooded by endless popups and become useless). You need
explicitly open a new window with client side code and then send request to
the PDF page from there. Say, you have a button, on its "onclick" event, you
add javascript like this:

var win=window.open("MyGetPDFPage.aspx?PDFID=xxx","PDFWindow");
win.focus();

> Hi, this has been asked so many times before but I cannot get an answer
> that works.
[quoted text clipped - 30 lines]
> Response.Flush()
> Response.Close()
bbulsara23@hotmail.com - 10 Jan 2006 14:52 GMT
Thanks for your prompt reply Norman. I accidently posted to *.adonet
rather than *.aspnet. I posted a retraction. I might get some new
glasses.

I still don't understand though. I have posted bits of my Page_Load and
button click procedures. Where exactly do I add your Javascript to open
the new window for each document.

Your code is below.

> var win=window.open("MyGetPDFPage.aspx?PDFID=xxx","PDFWindow");
> win.focus();

Here is my code for "WebForm2.aspx". As it is now it works and
retrieves 11 (although the number changes) documents from an Access
database. It displays 11 buttons on the page. When I click on the 4th
button, I get the 4th document as a PDF in the same browser window. I
would like this to be in a new browser window.

Thank you for your patience.

Barry

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim b As Button
Dim i as Integer
For i As 0 To getCVCount() - 1
 b=New Button()
 b.Text=BUTTONNAMES(i)
 Session.Add("cv" + b.GetHashCode.ToString(),getCVfromDB(i))
 AddHandler b.Click, AddressOf buttonClick
Next i
End Sub

Private Sub buttonClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim myCV As Object
myCV=Session.Item("cv"+sender.GetHashCode().ToString());
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "inline; filename=cv.pdf")
Response.AddHeader("Content-Type", "application/pdf")
Response.WriteFile(myCV.ToString())
Response.Flush()
Response.Close()
End Sub
Norman Yuan - 10 Jan 2006 20:07 GMT
As I mentioned in previous reply, you cannot open new window from server
side. So your logic of work would be to write two (or more) .aspx page. The
first page would provide 11 buttons which would all have client side
javascript code attached that opens new browser window. This page does not
post back to get the PDF (or other files you are to stream back to client).

So, in the first page, you may have code like this (C#):

private void Page_Load(....)
{
   if (!Page.IsPostBack)
   {
       //Attach client side code to the button(s), so clicking it would
open a new window
       btnPDF.Attributes.Add("onclick","OpenNewWindow('PDF');return
false;");
       btnDOC.Attributes.Add("onclick","OpenNewWindow('DOC');return
false;");
   }
}

Then in the page's HTML view, add following javascript to <Header> section
<Script Language="javascript">
function OpenNewWindow(fileType)
{
   var win;
   switch(fileType)
   {
       case "PDF"
           win=window.open("GetPDF.aspx","NewWindow");
           break;
       case "DOC"
           win=window.open("GetDOC.aspx","NewWindow");
           break;
       .......
   }
   win.focus();
}
</Script>

You can see here, you may have one or more aspx pages that is opened in new
window and requests the pdf (or other files).

> Thanks for your prompt reply Norman. I accidently posted to *.adonet
> rather than *.aspnet. I posted a retraction. I might get some new
[quoted text clipped - 42 lines]
> Response.Close()
> End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.