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

问题描述:

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

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);

干杯!