Results 1 to 1 of 1

Thread: download file with progress bar (Solved)

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2003
    Posts
    51

    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
    Last edited by vutle; Apr 25th, 2004 at 08:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width