在ASP.NET中下载没有弹出窗口的文件 [英] Download file without popup in ASP.NET

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

问题描述

我正在使用代码下载文件

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?

推荐答案

我得到了答案。
我删除属性并添加点击事件。

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天全站免登陆