VB.NET - Concatenate Multiple Files into single File



Cheat Sheet to concatenate Files

 Private Sub ConcatenateFiles(ByVal DestinationFileName As String, ByVal strHeaderText As String, ByVal ParamArray srcFiles() As String)
        Dim FileWriter As System.IO.StreamWriter
        Dim FileReader As System.IO.StreamReader
        Dim SourceFile As String
        'Create the desitnation file
        If File.Exists(DestinationFileName) = True Then
            File.Delete(DestinationFileName)
        End If
FileWriter = New StreamWriter(DestinationFileName, True)
For Each SourceFile In srcFiles
'Write the header string on the top of each file contents
FileWriter.WriteLine(strHeaderText)
'Open the source file in read mode
FileReader = New StreamReader(SourceFile)
'Append content of the current file in the destination file
FileWriter.Write(FileReader.ReadToEnd() & Environment.NewLine)
Next
End Sub

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.