Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stream does not return the same amount of bytes
Message
De
13/02/2013 20:20:27
 
 
À
13/02/2013 11:18:34
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01565895
Message ID:
01565972
Vues:
33
With this approach, I am able to obtain a copy which is the same as the source:
                    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 Using
The 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 Namespace
I basically add each file into the collection by calling the AddFile() method. Then, I call the CreateFile() method once ready.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform