views:

59

answers:

2

I need to load some image files in my application, and I want to just build them into the application instead of having the user point to their path. So I think I need a resource file. But I'm having a little trouble figuring out how to create a resource file and add it to my application.

+2  A: 

You can add the file to your project by choosing Add Existing Item from the project menu. Then, in properties for the file (hit F4), choose that Build Action should be "Embedded Resource". Then your file will be embedded in the assembly.

You can get to the file by using Assembly.GetManifestResourceStream:

Type t = typeof(SomeType);
Stream embeddedFileStream = t.Assembly.GetManifestResourceStream(t, "yourfilename.jpg")

The "SomeType" should be in the same assembly as the embedded resource, and you will need to specify the name of the file relative to the namespace location of the type.

driis
A: 

In Winforms you can do this:

  • Right click on the project in solution explorer
  • Click on properties
  • Click the Resources tab on the left
  • Click the middle link that will come up

Then all you do is go to properties > double click Resorces.resx > and go to Add Resource > Add Existing File

rmx