/// <summary>
/// 下载方法
/// </summary>
/// <param name="DownPath">文件路径如:\\Server5\document\或E:\\document\</param>
/// <param name="originalName">下载出来的文件名</param>
private void FileDownload(string DownPath, string originalName)
{
FileStream fs = new FileStream(DownPath, FileMode.Open, FileAccess.Read);
string fileExt = Path.GetExtension(DownPath);
string mime = "application/msword";
switch (fileExt)
{
case ".doc":
mime = "application/msword";
break;
case ".docx":
mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
break;
case ".ppt":
mime = "application/vnd.ms-powerpoint";
break;
case ".pot":
mime = "application/vnd.ms-powerpoint";
break;
case ".pps":
mime = "application/vnd.ms-pps";
break;
case ".pptx":
mime = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
break;
case ".xls":
mime = "application/vnd.ms-excel";
break;
case ".xlsx":
mime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
break;
case ".pdf":
mime = "application/pdf";
break;
case ".txt":
mime = "text/plain";
break;
case ".rar":
mime = "application/octet-stream";
break;
case ".zip":
mime = "application/x-zip-compressed";
break;
}
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = mime;
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode(originalName)); //文件名
Response.AppendHeader("Content-Length ", fs.Length.ToString());
Response.WriteFile(DownPath);
Response.Flush();
Response.End();
}