C#文件下载

string filepath = Server.MapPath("~/public/file.txt"); 
        FileInfo fi = new FileInfo(filepath);
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + fi.Name);
        Response.AddHeader("Content-Length", fi.Length.ToString());
        Response.ContentType = "application/octet-stream";
        Response.Filter.Close();
        Response.WriteFile(fi.FullName);
        Response.End();
原文地址:https://www.cnblogs.com/gaoyuchuanIT/p/1748242.html