【问题标题】:Ways to open Save as Dialog box on button click in asp.net在 asp.net 中单击按钮时打开另存为对话框的方法
【发布时间】:2017-11-02 06:52:54
【问题描述】:

有没有办法在asp.net中触发“另存为”对话框。我知道用 Java Script 来控制客户端的机器是不可能的。有什么方法可以在单击下载按钮时触发对话框。场景是我生成一个 XML,它必须下载到客户端的机器上。单击按钮时应弹出“另存为”对话框。提前致谢。

【问题讨论】:

标签: javascript c# jquery asp.net


【解决方案1】:

试试这个

String FileName = "FileName.txt";
String FilePath = "C:/...."; //Replace this
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName 
+ ";");
response.TransmitFile(FilePath);
response.Flush();
response.End();

【讨论】:

  • 谢谢,但我已经尝试过这段代码。这有助于拾取文件并将其下载到浏览器的默认文件夹中,并且不会触发“另存为”对话框。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-08
  • 2023-03-15
相关资源
最近更新 更多