如何强制下载对话框在服务器上的文本文件? [英] how to force download dialog for a text file on the server?

查看:150
本文介绍了如何强制下载对话框在服务器上的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制下载对话框在服务器上的文本文件?

how to force download dialog for a text file on the server?

当我用一击code这样的对话窗口是aspx文件。(为什么?)

when i used the blow code so the dialog window was for aspx file ... (why?)

    string FileBankPhysicalFolder = Server.MapPath("~/FileBanks/");
    string Name = "FileBank_" + "Melli_" + Session["Co_ID"].ToString() + "_" + RadcbDateOfPardakht.SelectedValue.Replace('/',',') + ".txt";
    string FileBankPath = FileBankPhysicalFolder + Name;
    string Content = Header + Body;
    System.IO.File.WriteAllText(FileBankPath, Content);

    Response.ContentType = "text/plain";
    Response.AppendHeader("Content-Disposition", "attachment;" +  Name);
    Response.WriteFile(FileBankPath);
    Response.End();

如何解决这个问题?

how can i fix this problem?

推荐答案

您应该发力下载标题与文件一起。我不知道你会怎么做,在ASP但基本上你要读一些ASP内置函数的文件然后将其输出到浏览器安装

You should send force-download headers along with the file. I don't know how you would do that in ASP but basically you have to read the file with some ASP built-in function then output it to the browser attaching

Content-Type: application/force-download;
Content-Disposition: attachment; filename=\yourfile.txt

您code上看:

Judging by your code:

Response.AppendHeader("Content-Type", "application/force-download;");
Response.AppendHeader("Content-Disposition", "attachment; filename="+ Name);

干杯!

这篇关于如何强制下载对话框在服务器上的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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