views:

46

answers:

1

In my MVC application I have the following paths;

  • /content/images/full
  • /content/images/thumbs

How would I, in my c# controller, get a list of all the files within my thumbs folder?

Edit

Is Server.MapPath still the best way?

I have this now DirectoryInfo di = new DirectoryInfo(Server.MapPath("/content/images/thumbs") ); but feel it's not the right way.

is there a best practice in MVC for this or is the above still correct?

A: 
Directory.GetFiles("/content/images/thumbs")

That will get all the files in a directory into a string array.

Daniel T.
@Daniel i can't get this to work. it maps at c:\content\images\thumbs rather than at my web application level.
griegs
Can you provide more info on what you're trying to do? It sounds like you're trying to return a list of file paths to the view. In that case, in the view, try using `<%= Server.MapPath(filePath) %>`, where filePath is a local path.
Daniel T.
Whoops, just noticed that `Server.MapPath()` actually converts a server path to a file path. Looking for some other solutions now...
Daniel T.
Thanks @Daniel.
griegs
I found this: http://stackoverflow.com/questions/3164/asp-net-absolute-path-back-to-web-relative-pathSeems a bit brittle though. I'd probably just get the filename using `Path.GetFileName(file)` and append the virtual path in front of it.
Daniel T.