• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

How to create a download link

Classic ASP VBScript

Hello.

I need assistance creating a straight download link in Classic ASP without having it try and play in the browser.

Just want it to prompt to "Save As".


Thanks!
Shane
0
lshane
Asked:
lshane
  • 4
1 Solution
 
themrrobertCommented:
Make a new asp page that will be the 'downloader'

have code like this:

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=test.txt"
Response.Write("Hello World")
Response.Flush

In this example, I just used text file as an example. If you need to force download like jpeg, you read the image binary file and then use Response.BinaryWrite() method to write binary data to the response stream.


http://codeissue.com/issues/i54dcd1e837e6e0/how-to-force-download-in-classic-asp
0
 
lshaneAuthor Commented:
Thank you, themrrobert.

The MP3 files are from relative paths stored in my Access database.

How can I extract just the MP3 file name from the relative path?
0
 
lshaneAuthor Commented:
Here is a link from a site I found from another site of a friend of mine.  (He's not a developer, or I would ask him).  lol


<a href="downloadmanager.asp?file=Harvest08-19-12cd.mp3&force=true"><img src="images/template/download.jpg" alt="Download" border="0" /></a>


How could I make this work with ASP?

The mp3 file needs to be dynamic.

The "downloadmanager.asp" file is completely blank.  It appears they are just pointing to it to "force" the "Save As" window.

====================================================================

Here is the excerpt of my repeat region, so you can see recordset nomenclature, etc.  The download line is at the bottom..

<%
sermoncount=0
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsSermons.EOF))
sermoncount=sermoncount+1
%>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="15%" rowspan="4" align="center" valign="middle" class="sermon-image"><img src="<%=rsSermons("sermonImage")%>" alt="speaker" width="100" border="0" align="absmiddle" /></td>
                              <td width="39%" nowrap="nowrap" class="sermon-title"><%=(rsSermons.Fields.Item("sermonTitle").Value)%></td>
                              <td width="7%" valign="middle">&nbsp;</td>
                              <td width="39%" valign="middle"><p id="audioplayer_<%=sermoncount%>"><a href="http://www.adobe.com/products/flashplayer/" class="audiotitle-middle">Requires Flash - Get it now!</a></p>
                              <script type="text/javascript">  
                    AudioPlayer.embed("audioplayer_<%=sermoncount%>", {soundFile: "http://www.islandchurchofwhidbey.org<%=(rsSermons.Fields.Item("sermonAudioPath").Value)%>",
                    titles: "<%=(rsSermons.Fields.Item("sermonTitle").Value)%>",  
                    artists: "<%=(rsSermons.Fields.Item("sermonSpeakerSalutation").Value)%> <%=(rsSermons.Fields.Item("sermonSpeakerFirst").Value)%> <%=(rsSermons.Fields.Item("sermonSpeakerLast").Value)%>",  
                    autostart: "no"  
                   
                    });  
                        </script>                                </td>
                          </tr>
                            <tr>
                              <td nowrap="nowrap" class="sermon-speaker"><%=(rsSermons.Fields.Item("sermonSpeakerSalutation").Value)%><em>&nbsp;</em><%=(rsSermons.Fields.Item("sermonSpeakerFirst").Value)%><em>&nbsp;</em><%=(rsSermons.Fields.Item("sermonSpeakerLast").Value)%></td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td nowrap="nowrap" class="sermon-date">(<%=(rsSermons.Fields.Item("sermonDate").Value)%> - <%=(rsSermons.Fields.Item("sermonAmPm").Value)%>)</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
<td nowrap="nowrap"><a href="downloadmanager.asp?file=Whatsyourname.mp3&force=true">Download</a>  


The "whatsyourname.mp3" is what needs to be dynamic, but I can't make it work.


Please help,
Shane
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Manuel Marienne-DuchêneITMCommented:
Use this code and save to dwfile.asp on your directory

<%
' Utilisation dans la pages
'	appel direct : /dwdFile.asp?DwdFile=chemin/du/fichier/fichier.ext
'   lien hypertexte : <a href="dwdFile.asp?DwdFile=chemin/du/fichier/fichier.ext" target="_self">

Dim sFilePath, sFileName, sFileUrl, iPosStart

sFileUrl = Request("DwdFile")
iPosStart = InStrRev(sFileUrl, "/")
sFileName = Right(sFileUrl, len(sFileUrl)-iPosStart)

'Lecture du fichier
Dim fso, oStream, sFileStream
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(Server.MapPath(sFileUrl)) Then
	Set oStream = CreateObject("ADODB.Stream")
	oStream.type = 1
	oStream.Open
	oStream.LoadFromFile Server.MapPath(sFileUrl)
	sFileStream = oStream.Read
	oStream.Close
	Set oStream = Nothing

else
	response.write "The file, named <i>"& sFileName &"</i>, doesn't exits!"
	response.end
end if
Set fso = Nothing


' Préparation des entêtes HTTP pour l'envoi de fichier
Response.AddHeader "Content-Type", "application/octetstream"
Response.AddHeader "Content-Disposition", "attachment; filename="""& sFileName &""""
Response.AddHeader "Cache-Control", "must-revalidate, post-check=0, pre-check=0"
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Expires", 0
'Transfer du fichier en flux binaire
Response.BinaryWrite sFileStream
%>

Open in new window


and in your code

<a href="dwdfile.asp?dwdfile=Whatsyourname.mp3" target="_self">Download</a>  

Open in new window

0
 
lshaneAuthor Commented:
Hi, manumd.

Perfect!

Thank you!
0
 
lshaneAuthor Commented:
Hi, manumd.

Suddenly something does not seem to be working properly.

Could you, please, join me in the current open thread:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_27873462.html#a38422608


Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now