如何在按钮单击时使用asp.net在浏览器中打开Word文件

时间:2017-04-24 12:19:56

标签: c# asp.net

每次下载文件而不是在新标签页中打开。我的代码是:

protected void bttnpdf_Click(object sender, EventArgs e)
{
    string FilePath = Server.MapPath("Road map.docx");
    WebClient User = new WebClient();
    Byte[] FileBuffer = User.DownloadData(FilePath);
    if (FileBuffer != null)
    {
        Response.ContentType = " application/vnd.openxmlformats-
        officedocument.wordprocessingml.document";
        Response.AddHeader("content-length", FileBuffer.Length.ToString());
        Response.BinaryWrite(FileBuffer);
    }
}

0 个答案:

没有答案