79304686

Date: 2024-12-24 03:55:41
Score: 0.5
Natty:
Report link
=> in design view remove any crystal report viewer control if placed and put below code

                <div id="divPDFView" runat="server" >
                </div>

=> Dont forget to create folder "PDFExports" in root 

=> Just call below function to show report. (Replace values with your values where '?' is placed and report should be in folder named "Reports" )

   private void ShowReport()
   {
            ReportDocument rd = new ReportDocument();

            rd.Load(Path.Combine(Server.MapPath("~/Reports"), "?ReportName.rpt"));

            //@@: Record Selection formula
            //rd.RecordSelectionFormula = "???";

            rd.SetDatabaseLogon(?UserId, ?Password, ?DbServer, "");

            //@@: Parameters
            //rd.SetParameterValue("cpf_1", "");  //String
            //rd.SetParameterValue("cpf_2", Convert.toInt32("1"));  //Int

            //@@: Parameters to Subreport
            //rd.SetParameterValue("cpf_????", "", rd.Subreports[0].Name);

            //@@: Set Title
            //rd.SummaryInfo.ReportTitle = "Report as on " + DateTime.Today.Day + "-" + DateTime.Today.Month + "-" + DateTime.Today.Year;

            //I use it for unique file names.. you can avoid it..
            Guid g = Guid.NewGuid();
            string strFileName = "?zReportName_" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "_" + Session["userId"].ToString() + "_" + g.ToString() + ".pdf";
            rd.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Path.Combine(Server.MapPath("~/PDFExports"), strFileName));

            divPDFView.InnerHtml = "<object data=\"PDFExports/" + strFileName + "\" type=\"application/pdf\" width=\"1230\" height=\"880\">  alt : <a href=\"PDFExports\\a.pdf\">PDF File</a> </object>";

            rd.Dispose();
            rd.Close();
      }
Reasons:
  • Blacklisted phrase (1): ???
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Ashif Pathan