0

Does anyone know how to iterate through images in a directory in asp.net razor pages?

8th Dec 2022, 12:24 PM
Will
2 ответов
+ 2
To iterate through images in a directory in ASP.NET Razor Pages, you can use the Directory.GetFiles method to get a list of file paths in the directory, and then iterate over the list using a foreach loop. Here is an example of how you can do this: @{ // Get the path to the directory containing the images var directoryPath = "path/to/directory"; // Get a list of files in the directory var imageFilePaths = Directory.GetFiles(directoryPath); } <ul> @foreach (var imageFilePath in imageFilePaths) { <li> <img src="@imageFilePath" /> </li> } </ul>
8th Dec 2022, 1:10 PM
Calviղ
Calviղ - avatar
0
Thanks Calvin! Will check it out!
8th Dec 2022, 1:32 PM
Will