Does anyone know how to iterate through images in a directory in asp.net razor pages? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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