I exported a crystal report to PDF.It's working normally in all browsers except Google chrome.Can anyone suggests any code to make it compatible with all browsers?The code i used to export is shown below

System.IO.FileStream fs = null;
                long FileSize = 0;
                DiskFileDestinationOptions oDest = new DiskFileDestinationOptions();
                string ExportFileName = Server.MapPath("\\CrystalReport1.rpt") + "Export";
                oRpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                oRpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                oDest.DiskFileName = ExportFileName;
                oRpt.ExportOptions.DestinationOptions = oDest;
                oRpt.Export();
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("Content-Type", "application/pdf");
                //Response.AddHeader("Content-Disposition", "attachment;filename=OnlineGO.pdf;");

                fs = new System.IO.FileStream(ExportFileName, FileMode.Open);
                FileSize = fs.Length;
                byte[] bBuffer = new byte[Convert.ToInt32(FileSize) + 1];
                fs.Read(bBuffer, 0, Convert.ToInt32(FileSize));
                fs.Close();
                Response.BinaryWrite(bBuffer);
                Response.Flush();
                Response.Close();

kindly anyone please help me to solve this thread
Thanks In advance
*Ranj*

Dani AI

Generated

A short diagnosis and a practical fix for 's export situation (and a note about 's client-side suggestion): Chrome's built‑in PDF renderer is stricter than some other browsers — when the server returns extra bytes, wrong headers, a non‑PDF filename, or an incomplete stream Chrome often shows "Failed to load PDF document" while Firefox/IE continue to render. Client-side advice (change the local viewer) can help individual testers, but the reliable solution is to make the response correct on the server. (stackoverflow.com)

Recommended server-side pattern (stream the report, set clean headers, avoid Response.End/Close). Export directly to a stream and copy it to the response so there is no temporary file to mishandle:

using (var ms = (System.IO.MemoryStream) reportDocument.ExportToStream(ExportFormatType.PortableDocFormat))
{
    Response.Clear();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "inline; filename=\"Report.pdf\"");
    Response.AddHeader("Content-Length", ms.Length.ToString());
    ms.WriteTo(Response.OutputStream);
    Response.Flush();
    HttpContext.Current.ApplicationInstance.CompleteRequest();
}
reportDocument.Close();
reportDocument.Dispose();

Crystal Reports has ExportToStream/ExportToHttpResponse helpers; when a disk file must be used, prefer HttpResponse.TransmitFile for large files rather than reading everything into memory. Both approaches avoid common pitfalls that trip Chrome. (learn.microsoft.com)

Avoid Response.End/Response.Close (they can abort threads or drop sockets) — use CompleteRequest after flushing so the pipeline completes cleanly. Also watch for stray HTML/BOM characters before the PDF header and make sure the exported filename ends with ".pdf" and the Content‑Length matches the bytes actually sent. These are frequent causes of Chrome-only failures. (learn.microsoft.com)

Quick troubleshooting checklist: 1) Save the generated file on the server and open it directly (confirms PDF validity). 2) Use Chrome DevTools (Network) or Fiddler to verify HTTP status, Content-Type, Content-Disposition and Content-Length. 3) If the file is valid locally but not in browser, fix headers/streaming; if every client downloads instead of viewing, remember Chrome can be set to "Download PDFs" in Site Settings (this is a client preference). ()

Just do this settings.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.