greglo
greglo

Reputation: 15

How to loop through image folder with paintings in Blazor server?

I am using Blazor server. I have paintings in a wwwroot/paintings folder. The painting names are all in the format "XX by YY". I need to generate links to each painting using its name, so the link will also say "XX by YY." I can't know the names ahead of time.

How can I load the paintings into an array, or what is the best way to do this?

Upvotes: 1

Views: 746

Answers (1)

Stefano Buzzoni
Stefano Buzzoni

Reputation: 94

This is what you are looking for:

DirectoryInfo d = new DirectoryInfo(@"...\wwwroot\paintings\");
FileInfo[] files = d.GetFiles();

foreach (FileInfo filepath in files)
    Console.WriteLine(filepath.Name);

last two lines just to print the names of all files you find. If needed you can specify file format in GetFiles() by putting for example "*.jpg" parameter

Upvotes: 1

Related Questions