download file with progress bar (Solved)
It's OK now.
Code:
Try
Dim wc As New WebClient
Dim i As Integer
Dim FileName As String = System.Windows.Forms.Application.StartupPath & "\da.txt"
Dim Finfo As New IO.FileInfo(FileName)
Dim st As Stream
Dim fn As New FileStream(System.Windows.Forms.Application.StartupPath & "\da2.txt", FileMode.Create)
Dim buf(256) As Byte
Dim o As Long
Dim NoOfByte As Integer
o = 0
' MsgBox(FileLen(FileName)) 'old way
If File.Exists(FileName) Then
NoOfByte = Finfo.Length
ProgressBar1.Maximum = NoOfByte
ProgressBar1.Minimum = 0
txtProgress.Text = NoOfByte
st = wc.OpenRead(FileName)
End If
'wc.BaseAddress = System.Windows.Forms.Application.StartupPath
' wc.DownloadFile()
Do
i = st.Read(buf, 0, 256)
fn.Write(buf, 0, i)
o += i
ProgressBar1.Value = o
Loop While (i <> 0)
fn.Close()
st.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try