protected void btnDownloadFile_Click(object sender, EventArgs e) { string fileFullPath = @"E:\AllFiles\History\John's certificate.doc"; FileInfo fileInfo = new FileInfo(fileFullPath); if (fileInfo.Exists) { Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileInfo.Name + "\""); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.ContentType = MIMETypeHelper.GetMimeType(fileInfo.Extension); // This method supplies the contenttype based on file extention for example if .doc extension returns application/msword Response.Flush(); Response.TransmitFile(fileInfo.FullName); Response.End(); } }
我注意到这是Chrome的功能,要关闭它,我执行了以下步骤: