0

I am using crystal report of VS 2008. I want to open a crystal report in PDF even when it is loaded with out showing the crystal report . I also not want to show the save dialog box while opening in PDF. With code below the report is opening directly in PDF but showing the save dialog box. How should i suppress the save dialog box and open the report directly in PDF?

CrystalReport1 oRpt = new CrystalReport1();
            
            DataSet ds = new DataSet();
            SqlDataAdapter adp0 = new SqlDataAdapter("SELECT * from test2", con);
            adp0.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                CrystalReportViewer1.SelectionFormula = "{test2.FirstName} = " + ds.Tables[0].Rows[0][0].ToString();
                CrystalReportViewer1.ReportSource = oRpt;
                
            }

            
            oRpt.Load(Server.MapPath("CrystalReport1.rpt"));
            ConnectionInfo connectionInfo = new ConnectionInfo();
            connectionInfo.DatabaseName = System.Configuration.ConfigurationSettings.AppSettings["DB"];
            connectionInfo.UserID = System.Configuration.ConfigurationSettings.AppSettings["UID"];
            connectionInfo.Password = System.Configuration.ConfigurationSettings.AppSettings["PWD"];
            connectionInfo.ServerName = System.Configuration.ConfigurationSettings.AppSettings["ServerName"];
            SetDBLogonForReport(connectionInfo, oRpt);
            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=testing.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();

Please any one help me to figure it out.Thanks In advance
*Ranj*

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by ranj_s20
0

I solved the problem.No need of this line of code
Response.AddHeader("Content-Disposition", "attachment;filename=testing.pdf;");

Thanks if any one tried 4 this

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.