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();
        });
    });
Kamil Będkowski
  • 1,092
  • 4
  • 16
  • 36
BlueChippy
  • 5,935
  • 16
  • 81
  • 131

2 Answers2

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

Community
  • 1
  • 1
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
1

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

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • :( 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 – BlueChippy Sep 10 '12 at 11:56
  • 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. – Jessica Shu Jan 28 '14 at 05:18