/// <summary> /// 下载文件 /// </summary> /// <param name="filePath">文件的路径</param> /// <param name="fileName">文件名(有时候文件名存在数据库中用于替换路径中的文件名)</param> public void FileDownLoad(string filePath, string fileName) { //判断文件是否存在 if (System.IO.File.Exists(filePath)) { FileInfo file = new FileInfo(filePath); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName));//解决中文文件名乱码 Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.Filter.Close(); Response.WriteFile(file.FullName); Response.End(); } }