1
幫助,爲奮力編寫代碼:Vb.Net - 通過數據庫文件名迭代,然後下載他們
以下功能將通過數據庫遍歷來獲取文件名,然後,如果存在,下載這些文件。我努力在這裏編寫代碼「在這裏下載文件代碼」。還需要它來返回ARRAY,它應該是已在此代碼中下載的文件的名稱。
任何人都可以請幫忙。
幫助,爲奮力編寫代碼:Vb.Net - 通過數據庫文件名迭代,然後下載他們
以下功能將通過數據庫遍歷來獲取文件名,然後,如果存在,下載這些文件。我努力在這裏編寫代碼「在這裏下載文件代碼」。還需要它來返回ARRAY,它應該是已在此代碼中下載的文件的名稱。
任何人都可以請幫忙。
不是數組的
Public Function DownloadFile(ByVal SourcePath As String, ByVal TargetPath As String) As Boolean
Dim DownloadFile As Boolean = False
Dim lvar_FileName As String = Nothing
Dim lvar_FileType As String = Nothing
Using Conn As New SqlConnection(ConnString)
SQLCommand = New SqlCommand("File_List",Conn)
SQLCommand.CommandText = "Select File_Name from File_List "
Try
Conn Conn.Open()
Dim reader As SqlDataReader
reader = SQLCommand.ExecuteReader()
While reader.Read()
'Code Here
lvar_FileName = reader(0)
'Download Files Code here
End While
Catch ex As Exception
End Try
End Using
Return DownloadFile
End Function
的問候,我會返回一個List(Of String)
,因爲它可以調整:
Public Function DownloadFile(ByVal SourcePath As String, ByVal lvar_TargetPath As String) As List(Of String)
Dim allFiles As New List(Of String)
Using Conn As New SqlConnection(ConnString)
Using SQLCommand = New SqlCommand("Select File_Name from File_List", Conn)
Try
Conn.Open()
Using reader = SQLCommand.ExecuteReader()
While reader.Read()
Dim fileName = reader.GetString(0)
Dim destPath = Path.Combine(SourcePath, fileName)
allFiles.Add(destPath)
End While
End Using
Catch ex As Exception
' Log exception here, otherwise don't catch it
End Try
End Using
End Using
Return allFiles
End Function
源路徑+文件名需要被複制到目標路徑+文件名。我們不在FILE TABLE中存儲源路徑或目標路徑,因此將其傳遞給函數。 –
@ConradJagger:使用'Path.Combine'。我編輯了我的答案以添加示例。但是,在上一條評論中,'lvar_TargetPath'或者'Destination Path'的含義仍然不清楚。 –