Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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/vb.net/17.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
Wpf 如何加载当前项目中的资源.rpt crystal报表文件_Wpf_Vb.net_Crystal Reports - Fatal编程技术网

Wpf 如何加载当前项目中的资源.rpt crystal报表文件

Wpf 如何加载当前项目中的资源.rpt crystal报表文件,wpf,vb.net,crystal-reports,Wpf,Vb.net,Crystal Reports,我已经创建了一个crystal报表,希望将其加载到ReportDocument。i、 e.加载(路径)方法。.rpt的生成操作是资源。.rpt文件与尝试加载它的.vb文件位于同一文件夹中 如果我指定直接路径,如“C:/PhotoCrystalReport.rpt”,它可以工作,但我想指定.rpt作为资源存储的路径,那么它找不到该文件。我尝试了下面的代码,但没有成功(完全相同的东西适用于图像资源,但不适用于.rpt) 也试过, cryRpt.Load("PhotoCrystalReport.rpt

我已经创建了一个crystal报表,希望将其加载到ReportDocument。i、 e.加载(路径)方法。.rpt的生成操作是资源。.rpt文件与尝试加载它的.vb文件位于同一文件夹中

如果我指定直接路径,如“C:/PhotoCrystalReport.rpt”,它可以工作,但我想指定.rpt作为资源存储的路径,那么它找不到该文件。我尝试了下面的代码,但没有成功(完全相同的东西适用于图像资源,但不适用于.rpt)

也试过,

cryRpt.Load("PhotoCrystalReport.rpt")

那么,有什么方法可以将此.rpt作为资源指向该位置吗?

我遇到了同样的问题,并在该链接中找到了解决方案:

MyReport.rpt文件的属性,并选择“始终复制”或“复制(如果更新)”

那么,我有没有办法把这个.rpt作为一个资源指向它的位置

没有

我最近也遇到了同样的问题,但据我所知,只有一种方法可以加载报表——CrystalDecisions.CrystalReports.Engine.ReportDocument.load()。此函数将文件名作为字符串,不会在程序集中查找嵌入式资源

因此,您有两种选择:

  • 从外部保存报告(即,将构建操作设置为“附加文件”,将复制到输出目录设置为“始终复制”或“更新时复制”),并按设计使用Load()。这就是大多数在线示例建议您继续的方式

  • 将报告提取到临时文件,并加载()该文件。完成报告后,不要忘记清理临时文件。关于如何做到这一点,有很多信息:

  • 我是这样做的:

    var temp = System.IO.Path.GetTempFileName();
    var assembly = System.Reflection.Assembly.GetExecutingAssembly();
    var stream = assembly.GetManifestResourceStream(@"Report.rpt");
    using (var fout = System.IO.File.Create(temp))
    {
        stream.CopyTo(fout);
    }
    
    后来:

    获取标识报表名称的字符串,在调试会话的中间使用VisualStudio即时窗口。在创建并运行程序集变量之后,我设置了一个断点:

    ? assembly.GetManifestResourceNames()
    

    好吧,上次我试过这个,没用。它现在起作用了。在尝试其他技术时,我删除了这个属性“CrystalDecisions.VSDesigner.CodeGen.ReportCodeGenerator”。我得把这房子放回去让它工作。谢谢史蒂夫!
    var temp = System.IO.Path.GetTempFileName();
    var assembly = System.Reflection.Assembly.GetExecutingAssembly();
    var stream = assembly.GetManifestResourceStream(@"Report.rpt");
    using (var fout = System.IO.File.Create(temp))
    {
        stream.CopyTo(fout);
    }
    
    if ((null != temp) && (System.IO.File.Exists(temp)))
    {
        System.IO.File.Delete(temp);
    }
    
    ? assembly.GetManifestResourceNames()