Imports System.IO
Imports System.IO.Directory
Imports System.Data.SqlClient
Imports System.Object
Imports System.Threading
Imports FileDownloader
Public Class downfile
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Button3 As System.Web.UI.WebControls.Button
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Private fdObject As New FileDownload()
Private theDownloadThread As Thread
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim path As Path
Dim filepath As String = Session("userdir")
ListBox1.BorderStyle = BorderStyle.Solid
ListBox1.BorderColor = Color.Chocolate
Dim fileEntries As String() = Directory.GetFiles(filepath)
Dim fileName As String = path.GetFileName(filepath)
For Each fileName In fileEntries
ListBox1.Items.Add(path.GetFileName(fileName))
Next fileName
End Sub
' this is my original download function
Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
Dim path As Path
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.AppendHeader("content-disposition", _
"attachment; filename=" + name)
End If
If type <> "" Then
Response.ContentType = type
End If
Response.WriteFile(fullpath)
Response.End()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FilesToDownload(20) As String
Dim ictr As Integer = 0
Dim DownLoadItem As ListItem
For Each DownLoadItem In ListBox1.Items
If DownLoadItem.Selected Then
FilesToDownload(ictr) = DownLoadItem.Text
' Response.Write(FilesToDownload(ictr))
End If
ictr = ictr + 1
Next
'Pass in the array to the FileDownload object.
fdObject = New FileDownload(FilesToDownload(ictr))
' I dont know what's next; how to call the startdownload