Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
Dim cmd As New SqlCommand
Dim conn As New SqlConnection
Dim dr As SqlDataReader
Dim sSql As String
sSql = "Select pathtofile from Jobs Where pathtofile = '" & Session("filename") & "'"
Try
If conn.State = ConnectionState.Open Then
conn.Close()
End If
conn.ConnectionString = Globals.GetConnectionString()
conn.Open()
With cmd
'make a connection
.Connection = conn
.Parameters.Add(New SqlParameter("@pathtofile", SqlDbType.Text)).Value = fname
.CommandType = CommandType.Text '.Text
.CommandText = sSql 'run sSql
'execute the data reader
dr = .ExecuteReader()
End With
Catch ex As Exception
MsgBox("Problems downloading file!!")
Finally
'dr.Close()
conn.Close()
End Try
'use the variable passed in the sub
Dim fullpath As String
fullpath = Path.GetFullPath(fname)
' dont change nothing below this line
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.AppendHeader("content-disposition", "attachment; filename=" + name)
'End If
If type <> "" Then
Response.ContentType = type
End If
Response.WriteFile(fullpath)
Response.End()
End Sub
Protected Sub uwgDownloadGrid_DblClick(ByVal sender As Object, _
ByVal e As Infragistics.WebUI.UltraWebGrid.ClickEventArgs) Handles uwgDownloadGrid.DblClick
Session("filename") = uwgDownloadGrid.Rows(uwgDownloadGrid.DisplayLayout.ActiveRow.Index).Cells(0).Value
Dim filename As String = Session("filename")
'Session("username") = e.Row.Cells(0).Text
DownloadFile(filename, True)
End Sub