如何将REPORT文件添加到RESX资源文件 [英] how to add a REPORT file to RESX resource file

查看:73
本文介绍了如何将REPORT文件添加到RESX资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2010中有一个小项目。在该项目中,我有一个名为MyResources.resx的资源文件。现在我使用这个MyResources.resx文件来存储我的项目中所需的图像。我还有一个名为REPORT1.rdlc的报告。我的目的是将该报告文件添加到MyResources.resx资源文件中。是否可以从该资源文件访问报告?



从以下示例中,我在MyResources.resx中存储了Thatha.jpg图像文件。和访问。



我的代码

I have a small project in VS2010.In that project I have one resource file called MyResources.resx. Now Iam using this MyResources.resx file to store the images required in my project.Also I have one report called REPORT1.rdlc. My Intention is to add that report file to that MyResources.resx resource file.Is it possible to access the report from that resouce file ?

From the below example, I stored Thatha.jpg image file in MyResources.resx. and accessed.

My Codes

ResourceManager rm = new ResourceManager("NewTest_EmbedRpt.MyResources", GetType().Assembly);
pictureBox1.Image = safe_cast<Image>(rm.GetObject("Thatha"));





同样可以存储Report1。 rdlc在资源方面可以访问吗?

任何代码和想法都会非常有用。



感谢您的指导。



Same way is it possible to store that Report1.rdlc in resources and can access?
Any codes and ideas will be very helpful.

Thanks for the guidances.

推荐答案

你不需要那样的东西。该功能基于自动生成的代码;并且它使得开发更不容易出错:几乎在所有情况下都没有拼写错误的资源名称,没有不安全的演员表。



让我们从图像开始。您可以在Visual Studio中添加图像并对其进行编辑,但我不建议这样做。考虑您创建了一些图像文件,例如Picture.png。在Visual Studio中创建一个resx节点,并使用添加现有文件来添加您的文件。该文件将1)添加到您的项目中(注意!它还会根据您的resx文件的位置将您的文件复制到项目目录中,因此请确保不会创建重复项;为此,不要手动添加); 2)文件节点的复制属性为无复制,因为该文件不应复制到输出目录,而是嵌入在程序集可执行模块中; 3)向资源添加对文件的引用; 3)在解决方案资源管理器中修改自动生成的代码文件,显示为resx节点的子节点。



打开此文件。您将找到一些名称接近文件名称的静态属性,在本例中为 Image Picture 。它的类型是 Image 。只需在代码中立即使用此属性。



对于某些未知的文件类型,例如* .rdlc,情况稍微复杂一些。如果文件不为Visual Studio所知,则属性类型为原始数据, byte [] 。将其反序列化是你的责任。但是您不需要使用资源流。如果你真的需要一个流,使用 MemoryStream 会更简单,更安全,因为当你刚读完该属性时内存就会被填满。



-SA
You don't need anything like that. The functionality is based on auto-generated code; and it make development much less error-prone: no misspelled resource names, no unsafe casts, in almost all cases.

Let's start with images. You can add an image and edit it in Visual Studio, but I won't recommend that. Consider you created some image file, such as "Picture.png". Create an resx node in Visual Studio and use "Add existing file" to add your file. The file will be 1) added to your project (attention! it will also copy your file to the project directory according to location of your resx file, so make sure no duplicate is created; for this purpose, don't add it manually); 2) the property "Copy" of the file node is made "No copy", because this file should not be copied to the output directory but embedded in your assembly executable module; 3) add a reference to the file to the resource; 3) modifies auto-generated code file shown as a child node of your resx node in Solution Explorer.

Open this file. You will find some static property with the name close to the name of your file, in this case, "Image Picture". It's type will be Image. Just use this property immediately in your code.

With some unknown file types, such as *.rdlc, the situation is a bit more complex. If the file is "not known to Visual Studio", the property type will be raw data, byte[]. It's your responsibility to deserialize it. But you don't need to use resource streams. In cases where you really need a stream, it's simper and safer to use MemoryStream, because memory is filled when you just read the property.

—SA


这篇关于如何将REPORT文件添加到RESX资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆