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

Time:08-24

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?

CodePudding user response:

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

  • Related