Question

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();
        });
    });
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top