Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

download of asp page

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I have the following problem.
I have 2 pages: Page1.asp & Page2.asp

I want visitors to be able to download Page2.asp when they click on a button on Page1.asp

An ordinary 'a href' won't do the trick because Page2 will be displayed in the browser window. The idea is that a save as dialog box appears... I have been searching for a solution all afternoon. Maybe some javascript could help?

I made it a simple example. In reality this is part of a file management page where users should be able to download all sort of files they uploaded before...

For now I'm using the following code:
If a visitor clicks on the 'download file' button the following page will be loaded in a new window:

<%
Set oFs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set oFile = oFs.GetFile(server.mappath(request.querystring(&quot;url&quot;)))

'request.querystring(&quot;url&quot;) contains the file that should be uploaded to the visitor (eg. files/somefile.asp)

Response.ContentType = &quot;application/x-msdownload&quot;
Response.AddHeader &quot;Content-Disposition&quot;, &quot;attachment; filename=&quot;&quot;&quot; & oFile.Name & &quot;&quot;&quot;&quot;
If (Right(request.querystring(&quot;url&quot;),3) <> &quot;asp&quot;) And (Right(request.querystring(&quot;url&quot;),3) <> &quot;asa&quot;) Then
Server.Execute request.querystring(&quot;url&quot;)
Else
Set oFileStream = oFile.OpenAsTextStream
response.write oFileStream.ReadAll
Set oFileStream = NOTHING
End If
Set oFile = NOTHING
Set oFs = NOTHING
%>

All help would be greatfully appreciated.
Thanks
Tomas
 
Sounds like you're knocking yourself out, when there's an easier way.... Just instruct the viewer to &quot;Save As...&quot; the next page...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top