我无法弄清楚如何让用户浏览本地计算机上的目录,并从我的ASP.NET Web应用程序中的服务器下载一些文件。这是我的代码,目前硬编码到文件夹。我希望用户能够选择一个文件夹并下载整个文件。为什么我不能在VB.NET中使用OpenFileDialog来让他们选择一个文件夹?
Protected Sub materialsClick(ByVal sender As Object, ByVal e As EventArgs)
Dim materialsButton As Button = sender
Dim rowIndex As Integer = Convert.ToInt32(materialsButton.Attributes("RowIndex"))
Dim presentationDate As Date = Convert.ToDateTime(gvPresentations.Rows(rowIndex).Cells(1).Text)
Dim format As String = "yyyy-MM-dd"
Dim convertedDate As String = presentationDate.ToString(format)
Dim dir As String = "\" + gvPresentations.Rows(rowIndex).Cells(0).Text & "\" & convertedDate
Dim publisherDir As String = "D:\Presentations" & dir
If Directory.Exists(publisherDir) Then
Dim materials() As String = Directory.GetFiles(publisherDir)
Dim newDir As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + dir
messageLabel.Text = newDir
Try
If Not Directory.Exists(newDir) Then
Directory.CreateDirectory(newDir)
End If
Catch ex As Exception
messageLabel.Text = "Could not download materials"
End Try
For Each material As String In materials
Dim fileName As String = Path.GetFileName(material)
If Not File.Exists(newDir & "\" & fileName) Then
File.Copy(material, newDir & "\" & fileName)
End If
Next
messageLabel.Text = "All files have been saved to " + newDir
Else
messageLabel.Text = "No materials available for this presentation"
End If
End Sub