【问题标题】:how to force download dialog for a text file on the server?如何强制服务器上的文本文件下载对话框?
【发布时间】:2011-04-23 05:04:44
【问题描述】:

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

当我使用打击代码时,对话框窗口用于 aspx 文件...(为什么?)

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

我该如何解决这个问题?

【问题讨论】:

    标签: c# asp.net dialog download


    【解决方案1】:

    您应该随文件一起发送强制下载标头。我不知道你会如何在 ASP 中做到这一点,但基本上你必须使用一些 ASP 内置函数读取文件,然后将其输出到附加的浏览器

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

    根据您的代码判断:

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

    干杯!

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 2021-08-20
      相关资源
      最近更新 更多