日期:2014-05-17  浏览次数:20991 次

在ASP.NET中实现如何下载txt及xml文件的方法.
string destFileName = "ok.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();
            }

?