Reputation: 16979
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.
Upvotes: 1
Views: 10760
Reputation: 4841
In Windows Forms you can do this:
Then all you do is go to properties → double click Resorces.resx → and go to Add Resource → Add Existing File.
Upvotes: 1
Reputation: 164341
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.
Upvotes: 3