打开一个新窗口codebehind ASP.net [英] Opening a new Window Codebehind ASP.net

查看:120
本文介绍了打开一个新窗口codebehind ASP.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

protected void Page_Load(object sender, EventArgs e)
{
        byte[] buffer = null;
        buffer = File.ReadAllBytes("C:\\myfile.pdf");
        HttpContext.Current.Response.ContentType = "application/pdf";
        HttpContext.Current.Response.OutputStream.Write(buffer, 0, buffer.Length);
        HttpContext.Current.Response.End();
}

我想开第二个窗口为当前页面,其中页面加载来自旁边的PFD文件。

I want to open a second window for the pfd file beside the current page, where the pageload comes from.

推荐答案

在为了做到这一点,你需要将PDF上传到一个路径在应用中它可以psented用户$ P $,然后注册一些JavaScript在新窗口中打开PDF:

In order to do this you'll need to upload the PDF to a path in the application where it can be presented to the user, then register some javascript to open the PDF in a new window:

protected void Page_Load(object sender, EventArgs e)
{
    byte[] buffer = null;
    buffer = File.ReadAllBytes("C:\\myfile.pdf");
    //save file to somewhere on server, for example in a folder called PDFs inside your application's root folder
    string newFilepath = Server.MapPath("~/PDFs/uploadedPDF.pdf");
    System.IO.FileStream savedPDF = File.Create(newFilepath);
    file.Write(buffer, 0, buffer.Length);
    file.Close();

    //register some javascript to open the new window
    Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenPDFScript", "window.open(\"/PDFs/uploadedPDF.pdf\");", true);
}

这篇关于打开一个新窗口codebehind ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆