0

I am writing an MVC3/Razor application and one of the requirements is for files to be generated and saved on the click of a button.

Generating the files and returning them to the browser as a FileResult is no problem, and for single files this is my preferred method - since it allows the user to open or save the file on their choice.

Prompt()ing the user in JavaScript to type a save folder location is also not a probem...however, this relies on them typing the complete path name correctly...and this can be a UNC share!

However, I want to be able to generate a whole set of files and pass in the path where they should be saved. The $.ajax(..) call is working and I can pass in the path from a textbox or prompt...but I'd like this to be some kind of folder browser.

$(document).ready(function () {
        $('#reportlink').click(function () {

        //REPLACE THIS V
        path = prompt('Please enter the path', 'd:\\');
        //REPLACE THIS ^

            $.blockUI({ message: '<div class="reportloading"><span class="reportloadingtext">Loading Report...</span></div>' });
            $.ajax({
                url: 'Report/All',
                type: 'POST',
                dataType: 'text/json;',
                data: { path: path },
                success: function (valid) {
                    if (valid) { alert('valid') }
                    else { alert('invalid') }
                }
            });
            $.unblockUI();
        });
    });
0

2 Answers 2

2

Unfortunately it is not possible with Javascript.

Please see these discussions...

How to write the Path of a file to upload in a text box?

Can't get the complete address while uploading a file

How to get the file path from HTML input form in Firefox 3

Sign up to request clarification or add additional context in comments.

Comments

1

It is not possible with JavaScript to have a folder browse input.

2 Comments

:( Thanks epascarello. You know of anything in HTML(5) to do the same? I might have to go with a "generate server-side, zip and return the zip" solution
Is it possible with another language? I am trying to make a chrome extension that automatically organizes where you save your downloads based on url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.