asp.net 服务器端下载文件

System.IO.FileInfo file = new System.IO.FileInfo(path);
                Response.Clear();
                Response.Charset = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // 添加头信息,为"文件下载/另存为"对话框指定默认文件名
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));
                // 添加头信息,指定文件大小,让浏览器能够显示下载进度
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "application/octet-stream";
                // 把文件流发送到客户端
                Response.WriteFile(file.FullName);
                // 停止页面的执行
                Response.End();

本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

posted @ 2007-07-13 18:02  音乐啤酒  阅读(372)  评论(0编辑  收藏  举报