I am having problem with writing PDF files to browser. Other mime types work fine. PDF files become corrupted.
FileInfo file = new FileInfo(Path.Combine(_module.FileDir, _file.FilePath));
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = _file.ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Regex.Replace(_file.FilePath, "\\s", "-"));
Response.AppendHeader("Content-Length", file.Length.ToString());
try
{
Response.WriteFile(file.FullName);
Response.Flush();
Response.Close();
}
catch
{
Response.ClearContent();
}