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(); }