10

We're currently in the process of developing a web-based application which will require the downloading of files through the browser. It would be ideal to have these files end up in a specific location on the file system.

Is there a way to make the file save and file open dialog default to a specific folder, such as %USER%\Downloads\MyApp\?

I don't want it to be a forced thing, but if we can get it to default to the desired location, it would at least be a good prompt for the user, and provide a better experience with other portions of the application.

I'm sure this can be done with a Java control, but it would be nice to be able to do it with some simple JavaScript or something instead.

Santosh Panda
  • 7,235
  • 8
  • 43
  • 56
Brian H
  • 833
  • 1
  • 5
  • 12

2 Answers2

8

Nope, I'm fairly sure this is not possible using JavaScript on any browser.

The only thing you can suggest is the file's name.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 1
    That's what I thought, but it doesn't hurt to ask just in case. :) – Brian H Dec 15 '10 at 19:18
  • Does someone know of a browser plugin for chrome or IE that could open access to this feature (despite security flaws) from javascript - preferably filtering by request origin? -Curious as I would like to use this in a intranet web application, and I do not want to embed the existing browser app in an exe if possible. – Chris Dec 09 '13 at 17:57
  • @BrianH you said "using JavaScript". Does this mean is it possible with some other language? I have a Java application (JSP) and we want to have a default download directory set for the user to download files (the same also when uploading files) – Marios Jun 23 '23 at 09:45
1

Since you are developing an App for internal use, you might have some influence on the browser that is used. As of spring 2022, Chrome, Opera, Edge support the File-System-Access-API which let you show a openFilePickerDialog or a saveFilePickerDialog which are independent from the default download location or the last file-upload path of the browser.

Once you have selected a file from the desired folder, this location will be stored in your browser preferences (I guess) and the following calls will directly open to this folder.

Take a look at this answer for further reading.

As shown here, it is then possible to specify in which folder the "file-dialog" should start:

const fileHandle = await window.showOpenFilePicker({
  startIn: 'pictures'
});

Instead of picturesyou can specify any "well-known" system folder, or if you program for a well known environment, any path that is likely to be found on the target machines.

nhaggen
  • 301
  • 2
  • 8