我的客户有一个要求。
他想通过单击按钮上传文件夹“D:/MyFolder/”中的所有文本文件。
所以我尝试了它,但我遇到了问题。
这是代码:
Protected Sub btnAutoUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAutoUpload.Click
Dim dbProvider As String
Dim dbSource As String
Dim con As New OleDbConnection
Dim SQL As String
Dim da As OleDbDataAdapter
Dim ds As New DataSet
'Connecting and retrieving data form Database.
dbProvider = "PROVIDER = Microsoft.Ace.OLEDB.12.0;"
dbSource = "Data Source = '" & Server.MapPath("~/App_Data/Data.accdb") & "'"
con.ConnectionString = dbProvider & dbSource
SQL = "SELECT * FROM tblUserDetails WHERE UserType = 'Company'"
da = New OleDbDataAdapter(SQL, con)
ds.Clear()
da.Fill(ds, "tblUserDetails")
Dim fileUploadPath As String = "C:/MUNIM/"
Dim NumberOfFilesToUpload As Integer = FileCount(fileUploadPath)
Dim Extension As String
Dim fileName As String
Dim files() As String
files = IO.Directory.GetFiles(fileUploadPath)
For x As Integer = 0 To NumberOfFilesToUpload - 1
Extension = IO.Path.GetExtension(files(x))
If Extension = ".txt" Then
fileName = IO.Path.GetFileNameWithoutExtension(files(x))
If fileName = ds.Tables("tblUserDetails").Rows(x).Item("FileName") Then
'Count the no. of document uploaders
Dim lineCount = IO.File.ReadAllLines(documentViewersPath).Length
'reading the names of document uploaders
Dim reader As New System.IO.StreamReader(documentViewersPath)
Dim allLines As New List(Of String)
Do While Not reader.EndOfStream
allLines.Add(reader.ReadLine())
Loop
reader.Close()
For i As Integer = 0 To lineCount - 1
If ds.Tables("tblUserDetails").Rows(x).Item("UserName") = ReadLine(i, allLines) Then
'Save the file to desired location (Upload File)
End If
Next
End If
End If
Next
End Sub
这怎么可能?
我应该使用 FileUpload 控件吗?
如果是,那么如何选择特定文件夹来上传文件?
或者我应该如何以编程方式将文件名提供给 FileUpload 控件?因为它是只读的。