简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM