Hi, I have this code for copying a file through a stream to get the progress of how many bytes i have transferred, this code works fine in stabile network environments, but I have tried to use this code transferring data with gprs mobile technology I get some problems if the connection is broken. is it possible to write some code that resume the copying after the connection is up again?

    Public Function VBCopyFile(ByVal paramFileFrom As String, ByVal paramFileTo As String) As Boolean
        Dim FileFrom As New FileStream(paramFileFrom, FileMode.Open, FileAccess.Read)
        Dim FileTo As New FileStream(paramFileTo, FileMode.Create, FileAccess.Write)
        Dim FileLengthFrom As Integer = FileLen(paramFileFrom)
        Dim lonCurByte As Long
        Dim Antall As Integer = 1024
        Dim Buffer(Antall - 1) As Byte
        Dim OK As Boolean = False


            Antall = FileFrom.Read(Buffer, 0, Antall)
            Do Until Antall = 0
                ' modify each byte in buffer here
                FileTo.Write(Buffer, 0, Antall)
                Antall = FileFrom.Read(Buffer, 0, Antall)

                lonCurByte += Antall
                RaiseEvent FileCopyProgress(lonCurByte, FileLengthFrom, paramFileFrom, paramFileTo)
            OK = True

        Catch ex As Exception
            OK = False
            Throw ex
            RaiseEvent FileCopyComplete()
        End Try
        Return OK
    End Function
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can declare a public flag (like the OK flag you have) and some public fields to carry information about last operation (file name, bytes transferred, etc...), so that when the connection is up again, you check for the last operation status. If "not OK", you can resume the copy operation according to the saved information.


  Nayer Naguib

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.