Solved

button to download a file

Posted on 2004-03-26
6
249 Views
Last Modified: 2011-09-20
hi,
i need to create a javascript or asp function that allow user to download a file he selected.

Suppose i have this table where I list files users can download  and a button
which allows user to download that file

<td> Nome file </td>
<td><input type ="Button" value ="Scarica"
onclick="download('myFileNamePath');"></td>

ok I need to let user download the file he selected by the function download
Solution can be made both by javascript or by javascript + asp.

Now I tried the second solution with no success: I open an asp file
where I send by get the filename path and add as the lines:

  response.ContentType = "application/octet-stream"
  response.AddHeader "Content-Disposition", "attachment; filename=" & request("file") & ";"

where 'file' is the file I want to let user download

but the IE always download the default asp page ... :-((((

My idea is simply to simulate the 'Save as' browser command
and open a window to ask user where he wants to save the file.

any idea or suggestion would be appreciated.

Thx
0
Comment
Question by:mandolino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 1

Expert Comment

by:Brandwood
ID: 10686062
<script language=javascript>
function download(locate){
window.open(locate)
}
</script>


<td> Nome file </td>
<td><input type ="Button" value ="Scarica"
onclick="download('myFileNamePath.zip');"></td>


make sure your file is of correct name,

.zip will automatically send to download.
0
 

Author Comment

by:mandolino
ID: 10687075
maybe i didn't explain well my problem...

I need a function, in asp or javascript, that let user download a file selected by an input button. This file may be a text file or a zip file or a pdf file.
The list of the files users can download is dinamically generated.

window.open opens file in a different window....
I need a function that opens a window to the user so he can choose where
to save the file he wants to download.
I need to bypass the explorer setting that decides if the file has to be downloaded or opened in the window.

In other words i need to simulate the 'saveas' command button
generated by a right-click on a file listed in the html page.

thanks
0
 
LVL 12

Accepted Solution

by:
lil_puffball earned 50 total points
ID: 10700285
Try this:

<script>
function saveFile(url){
  var obj=document.getElementById('saveframe');
  obj.src=url;
  setTimeout("window.saveframe.document.execCommand('SaveAs');",10);
}
</script>

File Name <button onclick="saveFile('file.htm');">Save</button><p>
File Name <button onclick="saveFile('file.zip');">Save</button><p>
File Name <button onclick="saveFile('file.pdf');">Save</button><p>

<iframe name='saveframe' id='saveframe' style='display:inline;width:500'></iframe>
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10700292
Change the iframe display to 'none' to hide it.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question