views:

1524

answers:

4

I'm creating an ASP.NET web application to schedule tasks on our server from a remote location using a .NET Wrapper for Scheduled Tasks. However, I'm stuck.

The user needs to be able to browse the file system on the server to retrieve a "file to run" for the new task that the user's creating in this application. I need to get the filepath/filename and pass it into the .NET wrapper.

I've tried using HTMLInputFile, but I haven't found a way to make that work for me.

Any help is appreciated.

Thanks


Update:
For this project, we've decided to simply list the executables in a dropdown box that would be available to users since they don't really need total access to the file system, just for security's sake.

A: 

The HTMLInputFile will only work on the client-side machine.

You need to write a filesystem browser in ASPX/HTML that browses on the server-side. Shouldn't be that hard to do.

You can't use the <input type="file" tag
This brings up a client-side dialog that browses the client machine.

tyndall
That's what I was afraid of. Thanks
Paxenos
A: 

As far as I am aware you need to create your own 'browser'.

eg You could use the My.Computer.Filesystem classes to retrieve a list of files in a folder and show those on the webpage. The user then selects the relevant file and posts a response back to the server.

geoff
+2  A: 

HTMLInputFile is used to browse the client's file system and upload a file to the server. It isn't used to browse the server's file system.

You will need something quite different. You will need some server side code to display the server side folder structure to the user via the browser.

There is an example of a basic implementation of this here.

Update:

With that sample, the path that you replace "yourfolderHere" with needs to be a virtual path, rather than an absolute path. So for example "C:\Inetpub\wwwroot\uploads" won't work, but "uploads" will work.

I hope it goes without saying that there are serious security issues to think about when implementing something like this.

andynormancx
Nice find, I was going to answer with a reference to this example but you just beat me to it.
Tim Cavanaugh
A: 

You can use System.IO.Directory to get directories and files. These can be displayed in a number of ways. A simple browser / file selection should be possible in less than 50 lines of code.

Also be aware that you may need to grant extra permissions to the user that your web app runs as so the file system is accessible.

There are also various security implications around this, so don't grant access to everything unless you really need this.

ck