简体   繁体   中英

Saving html file from server

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";
}

I think im on the right track. But when i try do save the html file (~100kb) the file never finishes downloading. Did i miss some required headers? Thanks

try this:

 Response.AppendHeader("content-disposition", "attachment; filename=test.html");
 Response.TransmitFile(Server.MapPath("~/SentinelOperationsUI/SoFaXML.html"));
 Response.End();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM