1

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?

1
  • In Blazor Server you can simply read all files using Directory.GetFiles. You'll then need to parse the filename as you want by yourself. Commented Aug 23, 2022 at 8:17

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

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.