Skip to content

Commit e1b1a2a

Browse files
authored
Merge pull request #56 from cdg191/patch-1
Fixed an issue where extra data was appended to end of downloaded file
2 parents bbe9ae2 + 4f4307b commit e1b1a2a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

Helpers.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,21 @@ private void StreamFile(string FilePath, string DownloadAs)
968968
DownloadAs = DownloadAs.Replace(" ", "_");
969969

970970
System.IO.FileInfo objFile = new System.IO.FileInfo(FilePath);
971-
System.Web.HttpResponse objResponse = System.Web.HttpContext.Current.Response;
972-
objResponse.ClearContent();
973-
objResponse.ClearHeaders();
974-
975-
objResponse.AppendHeader("Content-Type", MimeMapping.GetMimeMapping(objFile.Extension));
976-
objResponse.AppendHeader("Content-Disposition", "attachment; filename=" + DownloadAs);
977-
objResponse.AppendHeader("Content-Length", objFile.Length.ToString());
978-
objResponse.TransmitFile(objFile.FullName);
971+
972+
var b = File.ReadAllBytes(FilePath);
973+
974+
var Response = System.Web.HttpContext.Current.Response;
975+
976+
Response.Clear();
977+
Response.ContentType = MimeMapping.GetMimeMapping(objFile.Extension);
978+
Response.AppendHeader("Content-Disposition", "attachment; filename=" + DownloadAs);
979+
Response.AddHeader("Content-Length", b.Length.ToString());
980+
Response.Flush();
981+
Response.BinaryWrite(b);
982+
983+
HttpContext.Current.Response.Flush();
984+
HttpContext.Current.Response.SuppressContent = true;
985+
HttpContext.Current.ApplicationInstance.CompleteRequest();
979986
}
980987

981988
#endregion

0 commit comments

Comments
 (0)