1
public void SaveSofaXML(object s, EventArgs e)
{
    HttpResponse response = HttpContext.Current.Response;

    StreamReader streamReader = new StreamReader(
        Server.MapPath("~/SentinelOperationsUI/SoFaXML.html"));
    string text = streamReader.ReadToEnd();
    streamReader.Close();

    response.StatusCode = 200;
    response.ContentEncoding = Encoding.UTF32;
    response.AddHeader("content-disposition", "attachment; filename=test.html");
    response.AddHeader("Content-Transfer-Encoding", "binary");
    response.AddHeader("Content-Length", 
        response.ContentEncoding.GetByteCount(text).ToString());
    response.ContentType = "application-download";
}

我认为我在正确的轨道上。但是当我尝试保存 html 文件(~100kb)时,文件永远不会完成下载。我错过了一些必需的标题吗?谢谢

4

1 回答 1

4

试试这个:

 Response.AppendHeader("content-disposition", "attachment; filename=test.html");
 Response.TransmitFile(Server.MapPath("~/SentinelOperationsUI/SoFaXML.html"));
 Response.End();
于 2012-04-19T13:08:54.173 回答