?
Solved

C#  GetManifestResourceStream - how to reference an embedded resource

Posted on 2011-04-20
6
Medium Priority
?
1,132 Views
Last Modified: 2012-05-11
Hi..
I have an image file in a project under an images folder.  
...images/myImage.png

How do I reference it in GetManifestResource stream?
It's an embedded resource.

GetManifestResourceStream('MyAssembly.resources.myImage.png') does not work... what should it be..

0
Comment
Question by:JElster
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35437108
You can do this:
System.Drawing.Image myImage = System.Drawing.Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyAssembly.resources.myImage.png"))

Open in new window


Use:
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()

Open in new window

To read yours resources names.
0
 
LVL 1

Author Comment

by:JElster
ID: 35437271
None of the resource names have the image file in it.
When I  'add the name'  I get invalid parameter
0
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 2000 total points
ID: 35437288
Check the file properties in your project, "Build Action" must be set to "Embedded Resource"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35437750
Just FYI, for WinForms you can also do something like:

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(this.GetType(), "myImage.png");
            pictureBox1.Image = bmp;
        }
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35437794
Hello Idle_Mind, mmm I see, I tested it, just I have to remove the root namespace from the resource name to make it work. thank you.
0
 
LVL 1

Author Comment

by:JElster
ID: 35438484
thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question