--下载方式
FileInfo DownloadFile = new FileInfo(filePath);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
--直接浏览的方式
//FileStream fs = new FileStream(filePath, FileMode.Open);
//byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length);
//fs.Close();
//Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
//Response.BinaryWrite(bytes);
//Response.Flush();
//Response.End();