public ActionResult GenerateReport1()
        {
            DB50Entities db = new DB50Entities();
            var          c  = db.Report1();

            CrystalReport1 r = new CrystalReport1();

            r.Load();

            Stream s = r.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            return(File(s, "application/pdf"));
        }
        /// <summary>
        /// Download PDF of all employees
        /// </summary>
        /// <returns></returns>
        public ActionResult ExportEmployees()
        {
            List <Employee> allCustomer = new List <Employee>();

            allCustomer = db.Employees.ToList();


            CrystalReport1 rd = new CrystalReport1();

            rd.Load(Path.Combine(Server.MapPath("~/CrystalReports"), "ReportCustomer.rpt"));

            rd.SetDataSource(allCustomer);

            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();


            Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            stream.Seek(0, SeekOrigin.Begin);
            return(File(stream, "application/pdf", "EmployeeList.pdf"));
        }
Esempio n. 3
0
        public ActionResult ExportReport()
        {
            CrystalReport1 rd = new CrystalReport1();

            rd.Load(Path.Combine(Server.MapPath("~/Reports/CrystalReport1.rpt")));
            rd.SetDatabaseLogon("sa", "p@ssw0rd");
            rd.SetDataSource(context.Positions.ToList());
            foreach (Table tbl in rd.Database.Tables)
            {
                tbl.LogOnInfo.ConnectionInfo = connectInfo;
                tbl.ApplyLogOnInfo(tbl.LogOnInfo);
            }

            DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
            ExportOptions           CrExportOptions;
            PdfRtfWordFormatOptions pdfFormatOptions = new PdfRtfWordFormatOptions();

            CrDiskFileDestinationOptions.DiskFileName = "D:\\";
            CrExportOptions = rd.ExportOptions;
            {
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                CrExportOptions.DestinationOptions    = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions         = pdfFormatOptions;
            }

            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            Stream str = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            str.Seek(0, SeekOrigin.Begin);
            string savedFileName = string.Format("CrystalReport1_{0}", DateTime.Now);

            return(File(str, "application/pdf", savedFileName));
        }