Link to home
Start Free TrialLog in
Avatar of LDTK
LDTK

asked on

Downloading files in ASP

Hi I am trying to add a download facility to my web application. It was working ok until today but for some reason it is downloading the file name only instead of the file contents. i.e. when I open the file it only has the file name in it.I would really appreciate any help with this
Here is my code.

 Private Sub DownloadFile(ByVal fname As String)
        Dim path As System.IO.Path

        Dim forceDownload As Boolean

        forceDownload = True
        Dim fullpath = path.GetFullPath(fname)
        Dim name = path.GetFileName(fullpath)
        Dim ext = path.GetExtension(fullpath)
        Dim type As String = ""

        If Not IsDBNull(ext) Then
            ext = LCase(ext)
        End If

        Select Case ext
            Case ".htm", ".html"
                type = "text/HTML"
            Case ".txt"
                type = "text/plain"
            Case ".doc", ".rtf"
                type = "Application/msword"
            Case ".csv", ".xls"
                type = "Application/x-msexcel"
            Case Else
                type = "text/plain"
        End Select



        If (forceDownload) Then
            Response.Clear()
            Response.AddHeader("content-disposition", "attachment; filename=" & name)

        End If
        If type <> "" Then
            Response.ContentType = type
        End If

        Response.Write(fullpath)
        Response.End()

end sub

ASKER CERTIFIED SOLUTION
Avatar of arthuryeung
arthuryeung

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gladxml
gladxml

LDTK,

you can also try to check out the link might help...

http://www.aspemporium.com/aspEmporium/tutorials/vbs_download.asp
Another solution that worked for me with very little modification, the first try!:

http://www.asp101.com/articles/jason/filedownloadlist/default.asp
Hi LDTK, take a look at the following link.

Download option
https://www.experts-exchange.com/questions/20490839/Download-option.html

Regards,
Wakie.
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp


Cd&

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between arthuryeung, markhoy

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Programming_Gal
EE Cleanup Volunteer