How to get a particular image (as a Stream) from C# desktop application's \Resources folder?
In Visual Studio, I imported the image into the \Resources folder and it has a File Name
and a Full Path
property. I would like to use its name.
My goal is to do this:
System.IO.Stream contentStream = get the image stream from \Resources
System.Net.Mail.LinkedResource logo = new LinkedResource( contentStream);
You have a couple of simple options.
The /Resources folder is not exactly a special folder. You still have to select any item in the Solution Explorer that you want embedded into the assembly, and then, from the Properties window, specify that its build type is "Embedded Resource". Then use ResourceManager.GetStream to retrieve the contents as a stream.
The simpler method for most cases, though, is to use the Project Properties Designer window to add a Resources.resx file, then add the files you want to the Resources designer. For example, you can add images like this:
Visual Studio will generate code for you to retrieve the files you embed this way.