在RDLC报告中设定的图像源动态图像、报告、动态、RDLC

2023-09-03 11:05:36 作者:Bury.(埋葬)

我使用的是被捆绑在Visual Studio 2010中我已经定义,目前带有嵌入式图像的报告顶部品牌目的的RDLC文件的客户端的报告功能。图像标识为用户的公司。它没有任何关系的报告数据... ...它只是一个称号。

I'm using the client-side reporting capabilities that are bundled in with Visual Studio 2010. I've got an RDLC file defined, currently with embedded images for branding purposes at the top of the report. The image is the logo for the user's company. It has nothing whatsoever to do with the report data... it's just a title.

我希望能够打破依赖嵌入图像,我开始有规模的应用程序。相反,我希望能够动态地设置图像。不幸的是没有,这似乎支持这种参数类型。

I'd like to be able to break the dependency on embedding the images, as I'm beginning to have to scale the app. Instead, I'd like to be able to dynamically set the image. Unfortunately there is no parameter type that seems to support this.

我已经看了切换信号源从嵌入式到外部,也许发光徽标的图像文件在程序启动(徽标的被作为资源嵌入在一个单独的程序),然后将其称为一个一般命名文件的来源。我不知道我是多么喜欢这个选项,因为它似乎是一个黑客。测试明确设置路径的图像时,有效地称该对象未设置为一个实例,我也得到一个错误。例如,我甚至试图将其设置到D:\ test.jpg放在,并得到在设计时的错误...所以我更不愿意尝试这个选项

I've looked at switching the source from embedded to external, and perhaps emitting an image file of the logo at program launch (the logo's are embedded as resources in a separate assembly), then referring to it as a generically-named file for the source. I'm not sure how much I like this option, as it seems a hack. I also get an error when testing explicitly set path images, effectively saying the object is not set to an instance. For example, I've even tried to set it to D:\test.jpg, and gotten that error at design time... so I'm more reluctant to try this option.

我也看了从RDLC文件中调用类的引用程序集,但我似乎无法得到那个工作。它看起来像我可以引用组装,然后通过一个特殊的对象调用code调用。因为我的课是静态的,它应该C $ c.className.method是$,但似乎并没有工作。

I've also looked at calling a class in a referenced assembly from within the RDLC file, but I can't seem to get that to work. It looks like I can reference an assembly, then call via a special object called Code. Because my class is static, it should be Code.className.method, but that doesn't seem to work.

我也算打破了标题为子报表,但我仍然不认为我已经解决了我的依赖问题。它仍然需要维护的量相同。

I've also considered breaking the title into a subreport, but I still don't think I've solved my dependency problem. It would still require the same amount of maintenance.

我要指出,我使用对象作为我的数据源。我应该去哪个选项?我失去了一些东西明显?

I should mention that I'm using objects as my datasource. What option should I go with? Am I missing something obvious?

推荐答案

由于没有备用(或任何!)对此事的意见,我就进一步要求,并拿出一个可行的解决方案。

As there are no alternate (or any!) opinions on the matter, I've moved further along and have come up with a working solution.

我选择加入创建标志按需文件,将其存储在一个临时位置。如果该文件不存在,我就飞创造它。如果它确实存在,我只是引用一个存在的图像。

I'm opting to create an on-demand file of the logo, storing it in a temp location. If the file doesn't exist, I'm creating it on the fly. If it does exist, I'm just referencing the image that does exist.

在RDLC报告中,我创建了一个名为类型文本的Path参数。接下来,在属性的图片,我已经改变了的标志图像从嵌入式到外部,设置使用此图像是参数:[@Path]

In the RDLC report, I've created a parameter called Path of type Text. Next, in the properties for the Image, I've changed the logo image from embedded to external and set "Use this image" to be the parameter: [@Path].

那么,在code,我传递的文件路径为Path参数。但是,在我有previously了问题是,路径必须是一个网址,我一直试图通过在磁盘上的位置。所以,这部分应该是这样的:

Then, in the code I'm passing in the file path as the Path parameter. But where I had previously gone wrong is that the path has to be a URL and I had been attempting to pass the location on disk. So, that portion should look like this:

        ReportParameter paramLogo = new ReportParameter();
        paramLogo.Name = "Path";
        paramLogo.Values.Add(@"file:///C:\Users\Mike\AppData\Local\Temp\Logo.png");
        reportViewer.LocalReport.SetParameters(paramLogo);

我会说,MSDN文档可能会更好一点。为了他们的信用,有关于如何有所建树在更高层次上的许多详细的文档。这文章帮助。它清楚地说,我需要的URL路径,但它会一直更容易直接检查该财产在库中。然而,找到下级文件是困难和成果较少。这里是article该报告Image对象。没有太多的机会来设置需要的特性。

I will say that the MSDN documentation could be a little better. To their credit, there are many detailed documents about how to accomplish something at a higher level. This article helped. It clearly says that I needed a URL to the path, but it'd have been easier to examine that property directly in the library. However, finding the lower level documentation was harder and less fruitful. Here is the article for the Reporting Image object. There isn't much opportunity to set properties of interest.