using System.IO;

Directory.CreateDirectory(FilePath);

【使用WriteFile下载文件】

复制代码
using System.Net

private
string fileName = HttpContext.Current.Server.UrlEncode("规范.rar"); private string filePath = HttpContext.Current.Server.MapPath("规范.rar"); //使用WriteFile下载文件 protected void btnDL2_Click(object sender, EventArgs e) {   FileInfo info = new FileInfo(filePath);   long fileSize = info.Length;   Response.Clear();   Response.ContentType = "application/octet-stream";   Response.AddHeader("Content-Disposition", "attachement;filename=" + fileName);   //指定文件大小   Response.AddHeader("Content-Length", fileSize.ToString());   Response.WriteFile(filePath, 0, fileSize);   Response.Flush();   Response.Close(); }
复制代码
posted on 2014-04-30 16:56  知识天地  阅读(317)  评论(0编辑  收藏  举报