下载文件,而无需在ASP.NET中弹出 [英] Download file without popup in ASP.NET

查看:122
本文介绍了下载文件,而无需在ASP.NET中弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是code下载文件

I am downloading a file using the code

btnDownloadTemplate.Attributes.Add( "onClick", "window.open('StudyReport/WordReportTemplate.doc', 'OpenTemplate', 'resizable=no,scrollbars=no,toolbar=no,directories=no,status=no,menubar=no,copyhistory=no');return false;" );

这将显示一个弹出窗口并下载对话框所示。我怎样才能避免弹出,只下载对话框出现在屏幕上?

This will show a popup and the download dialog is shown. How can I avoid the popup and only the download dialog is on the screen?

推荐答案

我得到了答案。
我删除属性,并添加click事件,并在里面。

I got the answer. I remove the Attributes and add the click event and in it.

    string path = Server.MapPath("");
    path = path + @"\StudyReport\WordReportTemplate.doc";
    string name = Path.GetFileName( path );
    Response.AppendHeader( "content-disposition", "attachment; filename=" + name );
    Response.ContentType = "Application/msword";
    Response.WriteFile( path );
    Response.End();

这篇关于下载文件,而无需在ASP.NET中弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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