Reputation: 86987
How can I see all the images (*.jpg
and *.png
) in a folder, in my website?
All I can give is the location of the folder, but that is relative.
eg. ~/Images/Uploaded
or /Images/Uploaded
.
cheers :)
Upvotes: 1
Views: 3831
Reputation: 21888
Jon beats me to it but it may be worth mentioning the overload that takes a search pattern:
string[] files = Directory.GetFiles(Server.MapPath(path), "*.png");
You'll need to mix the results for the 2 image types.
Upvotes: 6
Reputation: 70379
Not sure what exactly you want to do BUT you need to first resolve the relative path to a "real one" using HttpContext.Current.Server.MapPath
- for an example see http://www.dotnetperls.com/mappath
Upvotes: 0
Reputation: 1502016
It sounds like you want:
var files = Directory.GetFiles(Server.MapPath(path));
In other words:
MapPath
to get from the web path to the file system pathDirectory.GetFiles
to find files on the file systemUpvotes: 7