1

需要帮助,因为努力编写代码:

下面的函数将遍历数据库以获取文件名,然后下载这些文件(如果存在)。我正在努力在这里“下载文件代码”中编写代码。还需要它返回 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

问候

4

1 回答 1

0

我将返回 a 而不是数组,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
于 2012-11-26T08:52:16.730 回答