Click here to Skip to main content
15,443,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my application I am using the crystal report. I want to save the crystal report as a pdf format into the folder in my application. When I click on the print button the pdf file is showing with datas and it is saving into the folder but the report which is saved inside the folder doesn't have any values. it is saving like a empty pdf file. How to save the report with datas into the folder. Can anyone help me to solve this problem. Here is code:

if (message == true & msgDocument == true)
                {
                    FillDetails();
                    DataSet dsQuotation = objQI.FillDataforPrint();
                    if (ViewState["WithTaxesId"].ToString() == "Y")
                    {
                        if (ViewState["ShowTaxesId"].ToString() == "I")
                        {
                            CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withtax-I.rpt");

                            string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withtax-I.rpt");
                            oRpt.Load(reportpath);
                        }
                        else if (ViewState["ShowTaxesId"].ToString() == "P")
                        {
                            CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withtax.rpt");
                            string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withtax.rpt");
                            oRpt.Load(reportpath);
                        }
                        else if (ViewState["ShowTaxesId"].ToString() == "S")
                        {
                            CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");
                            string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");
                            oRpt.Load(reportpath);
                        }
                    }
                    else if (ViewState["WithTaxesId"].ToString() == "N")
                    {
                        CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");

                        string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");
                        oRpt.Load(reportpath);

                    }
                    CrystalReportSource1.ReportDocument.Database.Tables["BidRequest"].SetDataSource(dsQuotation.Tables[0]);
                    CrystalReportSource1.ReportDocument.Database.Tables["BidProposalLineItems"].SetDataSource(dsQuotation.Tables[1]);
                    CrystalReportSource1.ReportDocument.Database.Tables["BidTandC"].SetDataSource(dsQuotation.Tables[2]);
                    CrystalReportSource1.ReportDocument.Database.Tables["BidBOQ"].SetDataSource(dsQuotation.Tables[3]);
                   
                    oRpt.SetDataSource(dsQuotation);                

                    if (dsQuotation.Tables[1].Rows.Count > 0)
                    {
                        CrystalReportViewer1.Visible = true;
                        CrystalReportViewer1.ReportSource = CrystalReportSource1;
                        CrystalReportViewer1.DataBind();                   
                        CrystalReportViewer1.Visible = true;

                    }
                }
                MemoryStream MemStream = new MemoryStream();
                MemStream = (MemoryStream)CrystalReportSource1.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                Response.Clear();
                Response.Buffer = true;
                Response.ContentType = "application/PDF";
                Response.BinaryWrite(MemStream.ToArray());
                string fileName = "Q" + SessionVarriables.BidIdSession + ViewState["Slno"].ToString().PadLeft(2, '0');
                string filePath = Server.MapPath("~/AttachDocument/") + fileName + ".pdf";

                ExportOptions rptExportOption;
                DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();
              
                string reportFileName = filePath;

                rptFileDestOption.DiskFileName = reportFileName;
                rptExportOption = oRpt.ExportOptions;
                {
                    rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
                   
                    rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
                    rptExportOption.ExportDestinationOptions = rptFileDestOption;
                    rptExportOption.ExportFormatOptions = rptFormatOption;
                   
                    
                }
                oRpt.Export();
               Response.End();


Thanks in Advance
Posted

1 solution

What version are you using?
It is pretty hard to say what you are doing wrong. But here are some websites and articles that might help you find the problem, and perhaps an alternative for what you are currently doing (shouldn't you use ExportToHttpResponse?).
I am assumung oRpt is a ReportDocument Object[^]?
MSDN has a link on the ReportDocument.Export Method[^] which is available since version 10.
And it seems ReportDocument.ExportToDisk[^] is even easier to use and is supported since version 9.
To export to a http response there is a likewise method, called ExportToHttpResponse[^] which is also explained here[^]. This is available since version 10.
Also, the manual provided by business objects[^] seems pretty comprehensive. Starting on page 191 the export options are discussed in detail. Things get more interesting around page 210 though.

Hope it helps! :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900