protected void btnOutput_Click(object sender, EventArgs e) { try { string fileName = this.hdnFilePath.Value; string fullFileName = Server.MapPath(fileName); FileInfo downloadFile = new FileInfo(fullFileName); // 文件存在 if (downloadFile.Exists) { 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.ASCII)); Response.AppendHeader("Content-Length", downloadFile.Length.ToString()); Response.WriteFile(downloadFile.FullName); Response.Flush(); Response.End(); } else { // 文件不存在 // TODO } } catch { // 文件打开异常 // TODO } }