views:

18

answers:

1

Hello, I was following the instructions in this book, chapter on Resources etc. and what I can't quite figure out is, how do I replace this:

images.Add(new BitmapImage(new Uri(@"/Images/Deer.jpg", UriKind.Relative)));
images.Add(new BitmapImage(new Uri(@"/Images/Dogs.jpg", UriKind.Relative)));
images.Add(new BitmapImage(new Uri(@"/Images/Welcome.jpg", UriKind.Relative)));

by a loop that would simply run through all embedded image resources to avoid hard-coding the image names and paths. How would I go about discovering the names of the embedded files?

I did select the images I wanted to embed and specified:

Build Action=Resource and Copy to Output Directory=Do not copy

in the Properties window. The assembly has grown considerably in size and I am quite convinced the images have indeed been embedded.

+2  A: 

try something using GetManifestResourceNames, or look into the ResourceManager object.

Assembly assembly = Assembly.GetExecutingAssembly();
foreach (string s in assembly.GetManifestResourceNames())
{
    //match on filenames here. you can also extention matching to find images.
}
Oren Mazor