I am using ASP.NET 4.5 with C#. 
I have created a web API that points to the folders out of my web-application to get some shared resources. Now, I want to retrieve the list of files from the directory to which the web-api call points. 
For example, my web application is resides on my local hard-drive's F:\Projects\Web1 directory. I have placed some images in C:\SharedRes\images directory. I have created a web-api that fetches images from this shared directory. For e.g. http://localhost/api/images/a.jpg will get the a.jpg from C:\SharedRes\images directory. It is working fine, but I want to get the list of files from C:\SharedRes\images whenever I make a call to web-api like http://localhost/api/images. 
I have tried following :
DirectoryInfo directoryInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath("http://localhost/api/images"));
FileInfo[] file = directoryInfo.GetFiles().Where(f => f.Extension == (".bmp") || f.Extension == (".jpg") || f.Extension == (".png") || f.Extension == (".TIFF") || f.Extension == (".gif")).ToArray();
But it gives URI format not supported error. 
Please let me know if any solution.
HttpServerUtility.MapPath method gets virtual path as parameter.
You should use HttpContext.Current.Server.MapPath("/api/images")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With