asp.net 文件下载技术

string filename = Session["file"] as string;
        string path = Server.MapPath("~/files/" + filename);
        if (File.Exists(path))
        {
            FileInfo fi = new FileInfo(path);
            Response.Clear();
            Response.ClearHeaders();
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8).Replace("+", "%20"));
            Response.AppendHeader("Content-Length", fi.Length.ToString());
            Response.WriteFile(fi.FullName);
            Response.Flush();
            Response.End();

        }
        else
        {
            Response.Write("文件不存在");
        }
posted @ 2011-08-13 12:47  solomon_Blog  阅读(254)  评论(0编辑  收藏  举报