Help with progressbar on file upload...

lidds

Junior Contributor
Joined
Nov 9, 2004
Messages
210
I am uploading a file into a image field within a table. I am using the following code but what I want to be able to do display a progressbar for the user. The problem is that I am struggling to work out how to do this.

Below is the code that I am using.

Code:
        Dim SourceLoc As String = "C:\temp\dxf file\exampleload.dxf"
        Dim myUploadCmd As New OleDb.OleDbCommand("UPDATE fileStorageTbl SET Picture=? WHERE Revision='0'", varProjSQLConn)
        Try
            Dim fileSize As New System.IO.FileStream(SourceLoc, IO.FileMode.Open, IO.FileAccess.Read)
            Dim b(fileSize.Length() - 1) As Byte
            objFrmStatus.txtStatus.Text = "Reading file, please wait..."
            objFrmStatus.Refresh()
            fileSize.Read(b, 0, b.Length)
            fileSize.Close()
            objFrmStatus.txtStatus.Text = "Uploading file to database, please wait..."
            objFrmStatus.Refresh()
            Dim p As New OleDb.OleDbParameter("@Picture", OleDb.OleDbType.LongVarBinary, b.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, b)
            myUploadCmd.Parameters.Add(p)
            varProjSQLConn.Open()
            myUploadCmd.ExecuteNonQuery()
            varProjSQLConn.Close()
        Catch ex As System.Data.SqlClient.SqlException
            MsgBox(ex.Message)
        End Try
        objFrmStatus.Close()
        MsgBox("File uploaded successfully", MsgBoxStyle.Information, "File Upload")

Thanks

Simon
 
You read the whole file by this single line

fileSize.Read(b, 0, b.Length)

so there won't be any intermediate step.

You have to break down this process into steps, say read 8k each time, in order to show the user the progress.
 
Back
Top