views:

41

answers:

2

I have a web application that receives a simple text file, but I need this file to be downloaded to a specific path. Meaning, when the application receives a text file, it will always be downloaded to a specific folder (for example, to C:\MyFolder). If it isn't possible, then I need to copy the file from where user has chosen to my folder.

This application is based on JavaScript.

+3  A: 

JavaScript cannot exert any control over my (the visitor's) local filesystem. I remain in complete control of where my downloaded files go, what they are named, and indeed whether I even want to download them in the first place.

Sorry, but the best you can do is inform your users where to put the file you're offering for download. You cannot use JavaScript to choose the destination yourself.

VoteyDisciple
Well, is it possible using some toolkit like dojo?
Dorr
Dojo is just JavaScript code. You cannot control download paths from a web browser using any technology. Any browser that allowed it would be exposing an ENORMOUS security hole. You could maliciously download a file to `C:\WINDOWS\` and gain control of your visitor's computer.
VoteyDisciple
Thanks for asking. Then, even using jsp is it impossible?
Dorr
Yes. JSP stands for Java **SERVER** Pages. That code executes on the server, where it has no connection to the visitor's computer. You can with JSP recommend a file **name** for the download (e.g., `foo.txt`) but the visitor can override that and it still gives you no control over the *path* where the file will get saved. The only way to control the path where a file goes is in an application running locally on the visitor's computer. Through the web it's simply not an option.
VoteyDisciple
Thank you very much for your answer.
Dorr
@Dorr, if you find an answer useful you should upvote the answer. If you consider your question to be answered, you should also "accept" the answer (by clicking the check mark beside the answer).
aioobe
A: 

You should be able to do this using a Java applet assuming that you have signed it. The user would be asked to allow your code to run and if allowed, you could do whatever you want: Including downloading a file to a specific location.

Chris Morrissey