1

I have a Asp.net MVC 3 project where I want to implement a textbox and a Browse button where I can browse on the path of the server /Content/Image and retrieve the filename of the file selected.

How to do it ?, as when I put in the view , it always browse the files locally, and what I want to do is to be able to Browse the /Content/Images from the server

tereško
  • 58,060
  • 25
  • 98
  • 150
dtjmsy
  • 2,664
  • 9
  • 42
  • 62

1 Answers1

0

You can not do that with standard controls. Traversing server filesystem in general poses high security risks and should be avoided as much as possible - so it's not implemented in any standard controls.

What you can do is implement separate controller action + view listing files on your server using usual C# classes from System.IO.

Sergey Kudriavtsev
  • 10,328
  • 4
  • 43
  • 68
  • ok, I understand that there is no native control which can traversing server filesystem, which leads me to wondering if it needs to be done with Action+Controller: is there any control out there which can get infos from the controller and display list files/folder in the view, browsing through its structure ? – dtjmsy Mar 14 '12 at 15:39
  • Never used such controls myself (for similar features I've written my own actually :)). You may want to try any available JavaScript-based TreeView control (first links in Google?) that supports loading data from JSON via AJAX requests and implement just a controller action that will return JSON-encoded file/directory list for specified directory. – Sergey Kudriavtsev Mar 14 '12 at 15:59
  • You may also want to check examples on existing File Managers implemented using MVC, for example, http://www.codeproject.com/Articles/159421/ASP-Net-MVC-Server-Explorer-Part-1 – Sergey Kudriavtsev Mar 14 '12 at 15:59
  • Thanks Sergey, that seems to be the only way to do. – dtjmsy Mar 15 '12 at 09:04