Click here to Skip to main content
15,741,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"));

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.

1 solution

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.

Share this answer
Paramu1973 5-Jul-14 1:42am    
Hi Sergey Alexandrovich Kryukov .....can you show me some sample codes? Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900