Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Hangfire&x2B;水晶报告电子邮件?_C#_Asp.net_.net_Crystal Reports_Hangfire - Fatal编程技术网

C# Hangfire&x2B;水晶报告电子邮件?

C# Hangfire&x2B;水晶报告电子邮件?,c#,asp.net,.net,crystal-reports,hangfire,C#,Asp.net,.net,Crystal Reports,Hangfire,我正努力做到这一点,这样我们就可以每天生成特定的报告,并通过电子邮件发送给列表中的一群人 我已经测试了Hangfire的重复性工作,效果很好。所以这不是一个问题。但我正在尝试从现有的Crystal报告文件(.rpt)创建报告。基本上我想这样做,当这个作业被执行时,代码将创建报告,以PDF格式保存到指定路径的磁盘上,然后我可以将其作为附件发送给人们。因此,没有必要在网页上看到报告。这样做的目的是在代码隐藏中生成报告,将其保存为PDF格式,并在保存后通过电子邮件发送给代码隐藏 我现在的问题与crys

我正努力做到这一点,这样我们就可以每天生成特定的报告,并通过电子邮件发送给列表中的一群人

我已经测试了Hangfire的重复性工作,效果很好。所以这不是一个问题。但我正在尝试从现有的Crystal报告文件(.rpt)创建报告。基本上我想这样做,当这个作业被执行时,代码将创建报告,以PDF格式保存到指定路径的磁盘上,然后我可以将其作为附件发送给人们。因此,没有必要在网页上看到报告。这样做的目的是在代码隐藏中生成报告,将其保存为PDF格式,并在保存后通过电子邮件发送给代码隐藏

我现在的问题与crystal报表的实际生成和保存有关。顺便说一句,我在测试中生成了一个excel文件,但我会将其更改为PDF格式以用于实际报告。这是我到目前为止生成报告的方法:

        string path = @"Save folder relative-path";
        //"report" is declared at the class level and instantiated below.
        report = new ReportDocument();
        report.SetDatabaseLogon(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]);
        report.Load(Server.MapPath("Relative path to the report"));
        report.SetDataSource(GetDataSet()); //This gets the dataset filled with data for the report

        try
        {
            ExportOptions options = new ExportOptions();

            DiskFileDestinationOptions diskFileOptions = new DiskFileDestinationOptions();
            ExcelFormatOptions excelOptions = new ExcelFormatOptions();
            diskFileOptions.DiskFileName = path + "Test Report.xls";

            options.ExportDestinationType = ExportDestinationType.DiskFile;
            options.ExportFormatType = ExportFormatType.Excel;
            options.ExportDestinationOptions = diskFileOptions;
            options.ExportFormatOptions = excelOptions;
            report.Export();

            /*
            This is where I would call a method to email the report to people
            */
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error generating report: " + ex.Message);
        }
此代码位于web应用程序的global.asax文件中的应用程序启动时调用的方法中。运行应用程序时,即使我知道代码中的路径正确,当我在Hangfire仪表板中查看失败的作业时,作业失败并抛出此错误:

System.IO.FileNotFoundException无法加载文件或程序集 'App_global.asax.twm32qri,版本=0.0.0.0,区域性=中性, PublicKeyToken=null'或其依赖项之一。系统不能 查找指定的文件

System.IO.FileNotFoundException:无法加载文件或程序集 'App_global.asax.twm32qri,版本=0.0.0.0,区域性=中性, PublicKeyToken=null'或其依赖项之一。系统不能 查找指定的文件。文件名:“App_global.asax.twm32qri, 版本=0.0.0.0,区域性=中性,PublicKeyToken=空'at' System.RuntimeTypeHandle.GetTypeByName(字符串名称,布尔值 throwOnError、布尔ignoreCase、布尔reflectionOnly、, StackScrawMarkHandle stackMark,IntPtr pPrivHostBinder,布尔值 loadTypeFromPartialName,ObjectHandleOnStack类型)位于 System.RuntimeTypeHandle.GetTypeByName(字符串名称,布尔值 throwOnError、布尔ignoreCase、布尔reflectionOnly、, stackcrawmark和stackMark,IntPtr pPrivHostBinder,布尔值 在System.Type.GetType(String typeName, 布尔值throwOnError,布尔值ignoreCase)位于 Hangfire.Storage.InvocationData.Deserialize()

警告:程序集绑定日志记录已关闭。要启用程序集绑定 记录失败,请设置注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog](DWORD)到1。注:有 某些性能损失是否与程序集绑定失败相关 登录中。要关闭此功能,请删除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]

编辑:

我也犯了另一个错误。这个有点关系 通过加载报告文件

失败执行作业期间发生异常。 CrystalDecisions.CrystalReports.Engine.LoadSaveReportException

无效的报告文件路径

CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: 无效的报告文件路径。在 CrystalDecisions.CrystalReports.Engine.Exception浏览器.ThrowenEngineException(字符串 messageID,EngineeExceptionErrorId)位于 CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(字符串 文件名,OpenReportMethod openMethod,Int16 parentJob)位于 CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport() 在 CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDatabaseLogon(字符串 用户,字符串密码),位于Intranet.Global.GenerateReport()中 path\Global.asax.cs:第98行


解决了这个问题。我显然需要使用CrystalReportViewer对象并将ReportDocument对象设置为其源。CrystalReportViewer类位于CrystalDecisions.Web命名空间中

using (ReportDocument report = new ReportDocument())
{
    using (CrystalReportViewer viewer = new CrystalReportViewer())
    {
        string path = System.Web.Hosting.HostingEnvironment.MapPath(@"Destination path here");
        report.Load(System.Web.Hosting.HostingEnvironment.MapPath(@"Path to .rpt file here"));
        report.SetDatabaseLogon(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]);

        string file = path + "TestReport.xls";

        //These two lines below are important. The report won't generate without them.
        viewer.ReportSource = report;
        viewer.RefreshReport();

        //Just deleting the file if it exists.
        if (File.Exists(file))
            File.Delete(file);

        report.ExportToDisk(ExportFormatType.Excel, diskFileOptions.DiskFileName);
    }
}

这个例外不是来自Crystal…不确定什么是hangfire,也不知道为什么你需要在web应用程序中编写这个,但显然它没有加载用于全局的程序集。asax@dotjoeHangfire是用来创建背景工作的,这些工作可以是随意的、延迟的,也可以是反复出现的。我的报告会重复出现,因为我会每天通过电子邮件发送报告。我知道错误不是来自crystal。但我不知道如何生成报告并将其保存到磁盘。导出到磁盘时会出现什么错误?目标目录的写入权限是否正常?@dotjoe我已在问题中包含了错误。这是System.IO.FileNotFoundException。写入权限确实存在。是的,但在您正确使用Crystal代码之前,就会触发该异常??