Improve company productivity with a Business Account.Sign Up

x
?
Solved

Force download when clicked (Save Target As...)

Posted on 2004-09-02
5
Medium Priority
?
1,534 Views
Last Modified: 2011-10-03
I would like to know of a script that forces a .mp3 or .wma, .rm file to download no matter what the users has set as a default for this file.  Same as if the user was to select the right click option:
"Save Target As..."

Example,
http://www.hydrozeen.com/Hydrozeen-Pile%20of%20Bones.mp3

Normally when you click on the basic link your computer settings will either stream this into your system or ask to download it.

Now you can always right click and then select:
Save Target As...
and this is what I would like the default for the link to be, so how do I change a basic .mp3 link into a force download link?

Thanks for the answer,
Stephen

0
Comment
Question by:lnternet
  • 3
4 Comments
 
LVL 15

Expert Comment

by:justinbillig
ID: 11964428
heres an example but it's ASP

http://www.psacake.com/web/if.asp
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 11964437
when the user clicks the link you could submit a download form to a new window then use that script on that page
0
 
LVL 3

Accepted Solution

by:
Ayesha_K earned 2000 total points
ID: 11964555
Hi,

I'm using the following function in ASP.NET to force the IE to download my file and not start opening it in its specified format.

    Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs)
        On Error GoTo errHandler
        Dim strPhysicalPath As String
        Dim objFileInfo As System.IO.FileInfo
        Dim ErrMsg As String

        strPhysicalPath = Server.MapPath(Session("MyFileName"))

        'exit if file does not exist
        If Not System.IO.File.Exists(strPhysicalPath) Then Exit Sub
        objFileInfo = New System.IO.FileInfo(strPhysicalPath)
        Response.Clear()

        Response.ClearHeaders()
        Response.Clear()
        Response.ContentType = "text/plain"
        Response.Charset = ""
        Response.AddHeader("Content-Disposition", "attachment;filename=" + objFileInfo.Name)
        Response.AddHeader("Content-Length", objFileInfo.Length.ToString())
        Response.WriteFile(strPhysicalPath)
        Response.Flush()
        Response.Close()
        Exit Sub

errHandler:
        ErrMsg = Err.Description
    End Sub
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12605959
I think the points should be split between myself and Ayesha_K since both are viable options
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

579 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