Open a PDF in a new window?

G

Guest

Hello,

I need to open a PDF file in a new window in ASP.NET 1.1.
The problem is when I try to save the open PDF file the suggested name is
name of my new window (ShowDocument -> ShowDocument.pdf), how can I set it up
so it can be the filename of the file?

I am doing the following, on the page with the link to the PDF file I

RegisterNewPdfWindow("../Common/ShowDocument.aspx?file="+file,"showdocument");

being RegisterNewPdfWindow

protected void RegisterNewPdfWindow(string path,string name)
{
RegisterClientScriptBlock("plugin.js","<script
src=\"../js/plugins.js\"></script>\n");
StringBuilder sb=new
StringBuilder("window.open(\"").Append(path).Append("\",\"").Append(name).Append("\");\n");
string block=ComposeScriptBlock(sb.ToString());
RegisterStartupScript("pdfwindow",block);
}

On the Page_Load of ShowDocument.aspx

private void Page_Load(object sender, System.EventArgs e)
{

Page.Response.ClearContent();
Page.Response.ClearHeaders();

Page.Response.ContentType = "application/pdf";

Page.Response.WriteFile(file);
Page.Response.Flush();
Page.Response.Close();
}

Thanks in advance
 
K

Kevin Spencer

Hi Pedro,

First, you don't need JavaScript to open a new window. You can use the
"target" attribute of a hyperlink, set to "_blank" to open the link in a new
window.

Now, if you want the URL in the Title bar to be the actual name of the file,
you have to request the actual name of the file, which can be done by
creating an HttpHandler class that handles requests for that file type
(".pdf" in this case). The HttpHandler does the same thing an ASP.Net Page
does (an ASP.Net Page is an HttpHandler), but is registered in IIS to handle
requests for certain file types.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
G

Guest

Hi Kevin,

I don't know if I could explain what I really need.
My problem is as I open the PDF file throw ShowDocument.aspx page when I try
to save that document (clicking on save button in the acrobat plugin) the
save dialog box sugest me the name ShowDocument.pdf and not the actual PDF
file name what was really wnat I wanted.

Pedro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top