Jan 20, 2010, 3:07 PM
Download and open a file in a separate window
Hi everyone, i have to open a pdf file in a separate window. I have tried with this:
Anyone of you know how it's possible to reproduce my wished behaviour?
Thank you.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="Sc1" runat="Server">
</ext:ScriptManager>
<ext:Button runat="server" ID="btnOk" Text="Ok">
<AjaxEvents>
<Click OnEvent="btnOk_Click" IsUpload="True">
</Click>
</AjaxEvents>
</ext:Button>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOk_Click(object sender, EventArgs e)
{
FileInfo file = new FileInfo(@"C:\Documents and Settings\koti\Local Settings\Temp\test.pdf");
// Checking if file exists
if (file.Exists)
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/pdf";
Response.TransmitFile(file.FullName);
Response.End();
}
}
}
but it opens the pdf file in the same and current window.Anyone of you know how it's possible to reproduce my wished behaviour?
Thank you.