Using loStreamDestination As System.IO.Stream = System.IO.File.OpenWrite(cDestination) Using loStream As System.IO.Stream = System.IO.File.OpenRead(cFile) loStream.CopyTo(loStreamDestination) End Using End UsingThe following is a class which is used to take a bunch of files and concatenate them together:
Namespace Framework Public Class CreateFileFromStream Public cFile As String = "" Public cMessage As String = "" Public lLogError As Boolean = True Public nFile As Integer = 0 Private oApp As Framework.App = Nothing Private oFile As Collection = New Collection Private oProcess As Framework.LXProcess = Nothing ' This is when we access the class in a desktop mode Sub New(ByVal toApplication As Framework.App) oApp = toApplication End Sub ' This is when we access the class in a Web or Web Service mode Public Sub New(ByVal toProcess As Framework.LXProcess) oProcess = toProcess oApp = oProcess.oApp End Sub ' Create the file Public Function CreateFile() As Boolean Dim lcFile As String = "" Dim loObject As Object = Nothing Dim llSuccess As Boolean = False ' Reset the values cMessage = "" Try ' Open the destination Using loStream As System.IO.Stream = System.IO.File.OpenWrite(cFile) ' For each file For Each loObject In oFile ' Initialization lcFile = loObject(1) ' Add them into the destination file Using loStreamCopy As System.IO.Stream = System.IO.File.OpenRead(lcFile) loStreamCopy.CopyTo(loStream) End Using Next End Using llSuccess = True Catch loError As Exception ' If we log the error If lLogError Then ' Get the proper definition as per the current scope If oProcess Is Nothing Then oApp.ErrorSetup(loError) Else oProcess.ErrorSetup(loError) End If End If cMessage = loError.Message End Try ' Reset the values lLogError = True nFile = 0 oFile.Clear() Return llSuccess End Function ' Add a file to the collection ' expC1 File Public Function AddFile(ByVal tcFile As String) As Boolean Dim loObject(1) As Object ' Initialization loObject(1) = tcFile oFile.Add(loObject) ' Initialization nFile = oFile.Count Return True End Function End Class End NamespaceI basically add each file into the collection by calling the AddFile() method. Then, I call the CreateFile() method once ready.