Search code examples
c#asp.netdirectory-structure

Get file paths from a folder


I am looking to get all the file paths from my images folder.

The file path in relation to my root is image/picture.jpg

I have seen the example of

foreach (var path in Directory.GetFiles(@"\image\"))

But this looks for a direct path, I am unsure as to how to use this code.

Can anyone suggest what I should be using?


Solution

  • Use Server.MapPath as so:

    foreach (var path in Directory.GetFiles(Server.MapPath( "~/image")))
    {
    
    }
    

    Server.MapPath returns the physical file path that corresponds to the specified virtual path on the Web server.