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 / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Open a PDF in a new window?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pedro - 24 Aug 2007 12:32 GMT
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
Kevin Spencer - 24 Aug 2007 13:14 GMT
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.

Signature

HTH,

Kevin Spencer
Microsoft MVP

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

> Hello,
>
[quoted text clipped - 36 lines]
>
> Thanks in advance
Pedro - 24 Aug 2007 15:28 GMT
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

> Hi Pedro,
>
[quoted text clipped - 49 lines]
> >
> > Thanks in advance
Patrice - 24 Aug 2007 16:14 GMT
Try the content disposition header to specify the file name
(http://support.microsoft.com/kb/260519/en-us but with inline rather than
attachment).

--
Patrice

> Hi Kevin,
>
[quoted text clipped - 66 lines]
>> >
>> > Thanks in advance

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.