protected void filedownload() { string destFileName = "temp.txt"; destFileName = Server.MapPath(".") + "\\" + destFileName; destFileName = Server.UrlDecode(destFileName); if (File.Exists(destFileName)) { FileInfo fi = new FileInfo(destFileName); Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.AppendHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(destFileName),System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Length",fi.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(destFileName); Response.Flush(); Response.End(); } }
亲试可用,留着备忘
原文链接:https://www.f2er.com/xml/297425.html