views:

113

answers:

1

I'm trying to find a way to implement file manager functionality in an mvc 2 application. I've looked at jquery etc for ways of doing this. I have been able to implement a simple upload/download functionality with just an input file button and so on, and I have also tried out jquery File Tree (http://abeautifulsite.net/blog/2008/03/jquery-file-tree/), but I have no idea how to connect the file tree functionality with the download, upload and delete functionality I want. Even though the file tree works, all it does if you click on a file is to show an alert with the name of the file. I don't know how to hook into this.

I would like something like the tree to the left with folders, and then the files to the right, with possibilites to select a file and then download or delete. The upload functionality I guess would be no problem, since I could just have that separate, and then reload the page so that the file tree updates. Although ideally I would have liked it to stay at the same selection.

Anyone have any ideas how to do this?

If not (or anyway) I would also very much appreciate if anyone knows of an open source file manager with these features (including upload/download/delete) in ajax/jquery or the like that is actually compatible with mvc2. The reason is I don't want to mess up the mvc application with web forms versions, which I do know of.

EDIT:

Here's the code that calls the fileTree function:

<script type="text/javascript">
    $(document).ready(function () {

        $('#JQueryFTD_Demo').fileTree({

            script: 'Home/JqueryFileTree',
            expandSpeed: 1000,
            collapseSpeed: 1000,
            multiFolder: true
        }, function (file) {
            alert(file); //This shows the name of the file if you click it
        });
    });
</script>

I can't read the fileTree funcion well enought to get where the file name is coming from (how it gets into the variable "file" here), and how I could hook into that to do different things with the file, such as deleting, downloading etc. Again, I'm very new to jquery so this is a bit above my head, I just need a file manager function that does these things and is compatible with the MVC way of thinking (i.e. not web forms based), so any other suggestions for "pre-baked code" would be fine, I don't have to understand it, just use it, and then I can learn jquery at my own pace :-).

A: 

If you are able to alert the selected filename you could send an AJAX request to a controller action passing this filename so that the server can take care of deleting the file. As far as downloading is concerned you could use a regular hyperlink to a controller action that will write the file contents in the response stream.

Darin Dimitrov
Ok, thanks, but that's too abstract for me I'm afraid. Sure, I could read up on the ajax request in the jquery documentation, but the alert is hooked to the click event (somehow, I don't understand the inner workings of the fileTree function very well). And I don't simply want to hook the click event to a delete call. Then all you can do is delete... I guess I would want to know how I can select a file and choose to download or delete etc. I'll add the code calling fileTree in my question.
Anders Svensson
After reading up on it a bit, this is pretty much what I ended up doing, so I'll take that as the answer! :-)
Anders Svensson