【ASP.Net】下载服务器端txt或者xml文件

前端之家收集整理的这篇文章主要介绍了【ASP.Net】下载服务器端txt或者xml文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
 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

猜你在找的XML相关文章