2

I'm trying to create a list with BitmapImages like this.

List<BitmapImage> Images = new List<BitmapImage>
{
    new BitmapImage(new Uri(@"/Images/Car.bmp", UriKind.Relative)),
};

Right now I'm adding one image manually from the resource \Images\, but I don't want to do that for all 68 images. Is there a way to make a method, that will look through the resources \Images\, and output a list of all the BitmapImage paths like above?

something like.

Foreach(Item in Images)
{
    List.add(ItemPath + ItemName)
}

Here is a picture of the folder am talking about:

Image of folder structure

1 Answer 1

8

Here how you can get files by pattern

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images");
foreach (string file in Directory.GetFiles(path, "*.bmp"))
{
    // there is file name
}
Sign up to request clarification or add additional context in comments.

1 Comment

@MongZhu updated answer, now here I get current folder of executing assembly and get all files by extension

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.