文件下载
public void daochu(string path,string name) {
if (File.Exists(path)) {
FileInfo file = new FileInfo(path);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(name, Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Lenght", file.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
//以字符流的形式下载
FileStream fs = new FileStream(path, FileMode.Open);
byte[] bytes = new byte[(int)file.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
//下载
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
}
浙公网安备 33010602011771号