How to make a file to be downloaded ..?

Need to do the show the file from db ,

 i have the file in the folder  and that filename inthe table ,

 how can i show that file to be downloadable .
this below CODE brings the FILENAME ...

but "couldnt" able to show the file ,

so that the user can download ....
plz suggest..?

Public Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
        con = New SqlConnection(ConfigurationSettings.AppSettings("str1"))
      cmd= New SqlCommand("Single_Date", con)
        cmd.CommandType = CommandType.StoredProcedure
        Dim parameter_Date As New SqlParameter("@_Date", SqlDbType.DateTime, 8)
        parameter_Date.Value = Calendar1.SelectedDate
        myDataReader = myCommand.ExecuteReader()
        Dim temp As String = ""
        'Dim Category As String
        Dim diffdbdate As DateTime
        While (myDataReader.Read())
            diffdbdate = myDataReader.Item("startdate")
            If (myDataReader.Item("freeregreq") = 1 And myDataReader.Item("escrow") = 1) Then
                temp &= "<br>name  :" & myDataReader.Item("cname") & "<br>Filedownload: " & myDataReader.Item("files") & ""
            End If
        End While
        Label1.Text = temp
    End Sub

Open in new window

LVL 18
Rajar AhmedConsultantAsked:
Who is Participating?
meeran03, do you have the folder as a virtual path? if so, then the http address with the location is sufficient.  You just need to append the file name from the db to the virtual path and assign it to the href of the hyperlink as
     temp &= "<br>name  :" & myDataReader.Item("cname") & "<br>Filedownload: <a href='http://projext/files/t/" & myDataReader.Item("files") & "'>" & myDataReader.Item("files") & "</a>"
assuming http://projext/files/t/ as your virtual path.

But, if you have the file in a shared location or in the file system, that do not have the virtual path then refer
Ken FayalCTOCommented:
You should put the file name in <A HREF> tags so that it will show as a link, but you have to provide the full path to the file.
Rajar AhmedConsultantAuthor Commented:
I dint see the file name  and there is a link field which shows url f:/projext/filesfilename.txt on the status bar..
temp &= "<br>name  :" & myDataReader.Item("cname") & "<br>Filedownload: <a href=""F:\projext\files" & myDataReader.Item("files") & """>"

Rajar AhmedConsultantAuthor Commented:
temp &= "<br>name  :" & myDataReader.Item("cname") & "<br>Filedownload: <a href=""http://F:/projext/files/t"">" & myDataReader.Item("files") & "</a>"

this is transfering the page to this url and loading the cannot open page rather than downloading the file
Rajar AhmedConsultantAuthor Commented:
thanks .. i created the virtual path and did...
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.

All Courses

From novice to tech pro — start learning today.