Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 

       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

Posted

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.

There is no spoon. <<The Matrix>>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...