Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
System.Windows.Forms.Application.DoEvents()
Button.Enabled = False
Dim CurrentOffSet As Long = 0
Dim ChunkSize = CInt(txtSize.Text) * 1024
Dim objFileInfo As New IO.FileInfo(OpenFileDialog1.FileName)
Dim lngFileLength = objFileInfo.Length
Dim strFileName = objFileInfo.Name
Dim StartTime = Now
Using objStreamReader = New IO.StreamReader(OpenFileDialog1.FileName)
Using objBinaryReader = New IO.BinaryReader(objStreamReader.BaseStream)
Dim lngOffSet = 0L
While lngOffSet < lngFileLength
If lngOffSet + ChunkSize > lngFileLength Then
ChunkSize = CInt(lngFileLength - lngOffSet)
End If
Dim Buffer = objBinaryReader.ReadBytes(ChunkSize)
objService.UploadFile("UploadedFiles\" & strFileName, Buffer, lngOffSet)
lngOffSet += ChunkSize
End While
objBinaryReader.Close()
objStreamReader.Close()
End Using
End Using
Button.Enabled = True
End If
End Sub
|