public static string GenerateExport(CrystalDecisions.CrystalReports.Engine.ReportDocument selectedReport, CrystalDecisions.Shared.ExportFormatType eft, string ExportFileName)
            {
                selectedReport.ExportOptions.ExportFormatType = eft;

                string contentType = "";

                // Make sure asp.net has create and delete permissions in the directory
                string tempDir = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["tempDir"]);
                string tempFileName = string.Concat(Path.GetFileNameWithoutExtension(selectedReport.FileName), ".");
                if (! string.IsNullOrEmpty(ExportFileName))
                {
                    tempFileName = string.Concat(ExportFileName, ".");
                }

                switch (eft)
                {
                    case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat:
                        tempFileName += "pdf";
                        break;
                    case CrystalDecisions.Shared.ExportFormatType.WordForWindows:
                        tempFileName += "doc";
                        break;
                    case CrystalDecisions.Shared.ExportFormatType.Excel:
                        tempFileName += "xls";
                        break;
                    case CrystalDecisions.Shared.ExportFormatType.HTML32:
                    case CrystalDecisions.Shared.ExportFormatType.HTML40:
                        tempFileName += "htm";
                        CrystalDecisions.Shared.HTMLFormatOptions hop = new CrystalDecisions.Shared.HTMLFormatOptions();
                        hop.HTMLBaseFolderName = tempDir;
                        hop.HTMLFileName = tempFileName;
                        selectedReport.ExportOptions.FormatOptions = hop;
                        break;
                }

                CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                dfo.DiskFileName = Path.Combine(tempDir, tempFileName);
                selectedReport.ExportOptions.DestinationOptions = dfo;
                selectedReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

                selectedReport.Export();
                selectedReport.Close();

                string tempFileNameUsed;
                if (eft == CrystalDecisions.Shared.ExportFormatType.HTML32 || eft == CrystalDecisions.Shared.ExportFormatType.HTML40)
                {
                    string[] fp = selectedReport.FilePath.Split("\\" .ToCharArray());
                    string leafDir = fp[fp.Length - 1];
                    // strip .rpt extension
                    leafDir = leafDir.Substring(0, leafDir.Length - 4);
                    tempFileNameUsed = string.Format("{0}{1}\\{2}", tempDir, leafDir, tempFileName);
                }
                else
                {
                    tempFileNameUsed = Path.Combine(tempDir, tempFileName);
                }

                return tempFileNameUsed;
            }
Example #2
0
        private void Mywork_OnDoWork(object sender, DoWorkEventArgs e)
        {
            using (ReportClass rptH = new ReportClass())
            {
                CrystalDecisions.Shared.PdfRtfWordFormatOptions         pdfOpts           = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions();
                CrystalDecisions.Shared.ExcelDataOnlyFormatOptions      excelOptsDataOnly = CrystalDecisions.Shared.ExportOptions.CreateDataOnlyExcelFormatOptions();
                CrystalDecisions.Shared.ExcelFormatOptions              excelOpts         = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions();
                CrystalDecisions.Shared.MicrosoftMailDestinationOptions mailOpts          = CrystalDecisions.Shared.ExportOptions.CreateMicrosoftMailDestinationOptions();
                CrystalDecisions.Shared.DiskFileDestinationOptions      diskOpts          = CrystalDecisions.Shared.ExportOptions.CreateDiskFileDestinationOptions();
                CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions();
                ReportDocument rpt = new ReportDocument();

                rpt.Load(file);

                pdfOpts.UsePageRange           = false;
                exportOpts.ExportFormatOptions = pdfOpts;

                excelOptsDataOnly.UseWorksheetFunctionsForSummaries = true;
                excelOptsDataOnly.MaintainColumnAlignment           = true;


                string MyRptName = rpt.FileName.ToString();
                //MyRptName = @"D:\ITProject\Tin\Tin2.xls";
                MyRptName = filepath + "\\" + filenameNoExtension + ".xls";
                //diskOpts.DiskFileName = "World Sales Report.pdf";
                diskOpts.DiskFileName = MyRptName;

                exportOpts.ExportDestinationOptions = diskOpts;

                //exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.MicrosoftMail;
                exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

                //exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.ExcelRecord;

                rpt.Export(exportOpts);
                for (int i = 0; i <= 100; i = i + 20)
                {
                    // Report progress to 'UI' thread
                    mywork.ReportProgress(i);
                    // Simulate long task
                    System.Threading.Thread.Sleep(100);
                }
            }
        }
Example #3
0
        private void btn_Change_Click(object sender, System.EventArgs e)
        {
            string filetype = "";

            filetype = ddl_FileFormat.SelectedValue;
            string contenttype = "";


            string myfilename = Request.MapPath(".") + "\\ReportExportFile\\" + Session.SessionID + "." + filetype;

            CrystalDecisions.Shared.DiskFileDestinationOptions mydiskfiledestinationoptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
            mydiskfiledestinationoptions.DiskFileName = myfilename;
            CrystalDecisions.Shared.ExportOptions myExportOptions = stafflistreport.ExportOptions;
            myExportOptions.DestinationOptions    = mydiskfiledestinationoptions;
            myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

            switch (ddl_FileFormat.SelectedItem.Value)
            {
            case "pdf":
                contenttype = "application/pdf";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                break;

            case "doc":
                contenttype = "application/msword";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
                break;
            }


            stafflistreport.Export();

            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = contenttype;
            Response.WriteFile(myfilename);
            Response.Flush();
            Response.Close();

            System.IO.File.Delete(myfilename);
        }
Example #4
0
        /// <summary>
        /// 把报表生成各种文件格式的文件(pdf,doc,xls)
        /// </summary>
        /// <param name="ReportName">报表名称</param>
        /// <param name="DS">数据源</param>
        /// <param name="DocumentName">导出的文件名</param>
        /// <returns></returns>

        public string ExportRpt(String ReportName, DataSet DS, string DocumentName)
        {
            try
            {
                ReportDocument rDoc = new ReportDocument();
                rDoc = ReturnReportDoc(ReportName, DS);
                CrystalDecisions.Shared.DiskFileDestinationOptions file = new CrystalDecisions.Shared.DiskFileDestinationOptions();


                file.DiskFileName = DocumentName;

                string FileName = "";
                FileName = DocumentName.Substring(DocumentName.Length - 3, 3).ToString();

                rDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                rDoc.ExportOptions.DestinationOptions    = file;

                if (FileName.ToLower() == "doc")
                {
                    rDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
                }
                else if (FileName.ToLower() == "xls")
                {
                    rDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
                }
                else
                {
                    rDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                }
                rDoc.Export();
                return("导出成功");
            }
            catch (Exception ex)
            {
                ErrorLogs(ex.ToString());
                return(ex.ToString());
            }
        }
Example #5
0
        private void btn_Change_Click(object sender, System.EventArgs e)
        {
            string filetype = "";
            filetype = ddl_FileFormat.SelectedValue;
            string contenttype = "";

            string myfilename = Request.MapPath(".")+"\\ReportExportFile\\"+Session.SessionID+"."+filetype;
            CrystalDecisions.Shared.DiskFileDestinationOptions mydiskfiledestinationoptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
            mydiskfiledestinationoptions.DiskFileName = myfilename;
            CrystalDecisions.Shared.ExportOptions myExportOptions = stafflistreport.ExportOptions;
            myExportOptions.DestinationOptions = mydiskfiledestinationoptions;
            myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

            switch(ddl_FileFormat.SelectedItem.Value)
            {
                case "pdf":
                    contenttype = "application/pdf";
                    myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                    break;
                case "doc":
                    contenttype = "application/msword";
                    myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
                    break;
            }

            stafflistreport.Export();

            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = contenttype;
            Response.WriteFile(myfilename);
            Response.Flush();
            Response.Close();

            System.IO.File.Delete(myfilename);
        }
Example #6
0
        public JsonResult SendMail(string Lab, string testid)
        {
            var    tosend = "*****@*****.**";
            string path   = "";
            PatientLabReportPrint rptPatientLabReports = new PatientLabReportPrint();
            DataSet ds = BL_obj.SendMail(Lab, testid);

            List <PatientLabReportPrint> searchlist = new List <PatientLabReportPrint>();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                searchlist.Add(new PatientLabReportPrint
                {
                    EmailID       = dr["EmailID"].ToString(),
                    EmailPassword = dr["EmailPassword"].ToString()
                });
            }



            ReportDocument crystalReport = new ReportDocument();                                      // creating object of crystal report

            crystalReport.Load(Path.Combine(Server.MapPath("~/Report"), "RptPatientLabReports.rpt")); // path of report
            crystalReport.SetDataSource(ds);                                                          // binding datatable



            //SetDataSource(ds);

            int    email1       = 0;
            string hospitalname = ds.Tables[0].Rows[0]["HospitalName"].ToString();
            string patname      = ds.Tables[1].Rows[0]["PatientName"].ToString();



            path = "c:\\LabReports" + "ss" + ".pdf";
            email1++;
            //CrystalDecisions.Shared.ExportOptions CrExportOptions;
            CrystalDecisions.Shared.DiskFileDestinationOptions CrDiskFileDestinationOptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
            CrystalDecisions.Shared.PdfRtfWordFormatOptions    CrFormatTypeOptions          = new CrystalDecisions.Shared.PdfRtfWordFormatOptions();

            var filename  = Path.GetFileName(crystalReport.FileName);
            var extention = Path.GetExtension(crystalReport.FileName);
            var filenamethoutextenction = Path.GetFileNameWithoutExtension(crystalReport.FileName);

            CrDiskFileDestinationOptions.DiskFileName = crystalReport.FileName;
            //CrExportOptions = rptPatientLabReports.ExportOptions;
            //{
            //    CrExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
            //    CrExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
            //    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
            //    CrExportOptions.FormatOptions = CrFormatTypeOptions;
            //}
            //rptPatientLabReports.Export();

            email1++;



            string email = ds.Tables[0].Rows[0]["EmailID"].ToString();
            string pass  = ds.Tables[0].Rows[0]["EmailPassword"].ToString();

            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            SmtpClient SmtpServer            = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress(email);
            mail.To.Add("*****@*****.**");
            // mail.Subject = txtSubject.Text;
            mail.Attachments.Add(new Attachment(@"C:\Users\Saurabh\Downloads\Nilesh (1).pdf"));



            SmtpServer.Port        = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "saurabh@123");
            SmtpServer.EnableSsl   = true;

            SmtpServer.DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network;
            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Send(mail);



            bool result = false;

            return(Json(result, JsonRequestBehavior.AllowGet));
        }