10

There's this Excel file I want users to be able to download from my server. There must be an easy way to initiate the download of the file after a click on the "Download" button... but I have no clue how to make that happen.

I have this so far: (VBscript and ASP)

<head> <script type="text/javascript" src="overzicht.js"></script> </head> Set fs=Server.CreateObject("Scripting.FileSystemObject") if (fs.FileExists("c:\file.xls"))=true then 'fake filename D: response.write("<input type='button' value='Download Masterfile' class='button' onclick='exportmasterfile();' /><br />") else response.write("Masterfile not found. <br />") end if set fs=nothing 

The JavaScript function is empty.

2
  • 2
    Write your comments using "add comment" link, not writing new answers... 1) The users will be notified; 2) You won't mix remarks and real solutions. Commented Dec 8, 2008 at 13:40
  • We get notifications for these? I "accidentally"ran into your comment after I checked my profile, no offence. Thanks :) Commented Dec 9, 2008 at 12:03

4 Answers 4

21

Actually, if you want a 'more-efficient' (and sexier) way, use:

location.href = your_url; 

That way, you will save the compiler some time in going up to the location's prototype chain up to the window object.

Sign up to request clarification or add additional context in comments.

Comments

19

Found it:

function exportmasterfile() { var url='../documenten/Master-File.xls'; window.open(url,'Download'); } 

Comments

5

If your server is configured to trigger a download for files of that mime type, it's as simple as this:

window.location = your_url 

Comments

1

Here's a VBScript function to download a binary file.

Function SaveUrlToFile(url, path) Dim xmlhttp, stream, fso ' Request the file from the internet. Set xmlhttp = CreateObject("MSXML2.XMLHTTP") xmlhttp.open "GET", url, false xmlhttp.send If xmlhttp.status <> 200 Then SaveUrlToFile = false Exit Function End If ' Download the file into memory. Set stream = CreateObject("ADODB.Stream") stream.Open stream.Type = 1 ' adTypeBinary stream.Write xmlhttp.responseBody stream.Position = 0 ' rewind stream ' Save from memory to physical file. Set fso = Createobject("Scripting.FileSystemObject") If fso.Fileexists(path) Then fso.DeleteFile path End If stream.SaveToFile path SaveUrlToFile = true End Function 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.