Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[VB] File Downloader With ProgressBar[VB]
#1
File Downloader With ProgressBar


Step 1: Setting Everything up

-Add a Webclient To your toolbox. Just right click to toolbox, click add items, and type in webclient on the filter to add it.
-Design your form... Mine is below...


Step 2: Coding Button

Double Click the button and add this code...
Code:
webClient1.DownloadFileAsync(New Uri("http://www.downloadlink.com/filename.exe"), Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/downloadedFile.exe")
You will need to edit the link ovbiously.
This Coding tells the webclient what to download and what the link is.

Step Three: Events

-Go to the Events of the WebClient. Go to DownloadProgressChanged and add this code...
Code:
progressBar1.Value = e.ProgressPercentage
-This updates the progressbar until it is complete.

You Are Done. If you want it to notify when the download is complete, you can add a messagebox or something under the downloadfilecomplete part of the events...

Sorry if its already posted, but i felt like making a tutorial.
Reply
#2
This will be very useful when I finish and release my Batch Tools V2 Program.
I don't think this was posted before but you can always use the search button if you are unsure.
Thanks Smile
Reply
#3
This will be very useful thanks for this


Aim = Pr8Source
Reply
#4
Cool mate very useful!
Reply
#5
Thanks for the tut, I'll open Visual Basics and test it out right now. Smile
Reply
#6
ALright. good luck. if you come across any problems, i can send you the source or just ask me
[Image: iddyEs.png]
Reply
#7
i will probably use this later, nice
Reply
#8
I mite use this for my auto update system.
Reply
#9
Here's a file downloader using a webrequest that I modified to my own purpose:

Code:
Imports System.Net
Imports System.IO

Public Class Form1

    Private Sub GetFile_Button(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'This can be changed
        Dim BuffSize As Integer = 1024
        Dim buffer(BuffSize) As Byte
        Dim size As Integer = 0
        Dim readbyte As Integer = 0

        Dim url As String = "MY FILE DOWNLOAD HTTP ADDRESS LOCATION"
        Dim req As HttpWebRequest = WebRequest.Create(url)
        Dim res As HttpWebResponse = req.GetResponse()
        Dim contents As Stream = res.GetResponseStream()

        Dim NewFile As New FileStream("C:\myfile.mp3", FileMode.OpenOrCreate, FileAccess.Write)

        'While size is not equal to -1
        While size <> -1
            size = contents.Read(buffer, 0, BuffSize)
            If size = 0 Then Exit While
            readbyte += size
            'Here is where you can display the amount of bytes downloaded in the form title
            Me.Text = readbyte & " bytes / " & FormatNumber((readbyte / 1024), 2) & " kb"
            'Show progress bar / status  

            If size < BuffSize Then
                Dim buff(size) As Byte
                Array.Copy(buffer, buff, size)
                NewFile.Write(buff, 0, size)
                buff = Nothing
            Else
                NewFile.Write(buffer, 0, size)
            End If

            Array.Clear(buffer, 0, size)
        End While

        NewFile.Close()
        contents.Close()
        'Here we clear the buffer array down to nothing
        buffer = Nothing
    End Sub
End Class

Works great, you can input the amount of bytes to download at a time so that your app doesn't freeze when downloading large files. The display get's put into the titlebar.

Amount of bytes to download in chunks can be changed through the buffer here:
Code:
Dim BuffSize As Integer = 1024

1024 is a byte conversion standard for 1kb, this can be changed depending on what you want
Reply
#10
Wow, Coding Support, another amazing release from you! Thank-you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [VB.Net] YouTube Video Downloader BlackSpider 18 20,182 10-13-2012, 06:31 AM
Last Post: DotNetDevil
  [VB.Net][SRC]ProgressBar Color HF~Legend 14 7,481 09-08-2012, 04:18 PM
Last Post: spesificrelax
  [Preview/] YouTube Downloader and Converter full FFMPEG, Massive conversion list 2012 FizzyMentos 3 2,102 02-04-2012, 02:35 PM
Last Post: Denny Crane
  [TUT]$hareCash Downloader[NEW] Prominent 41 12,932 10-11-2011, 04:27 PM
Last Post: Genuine
  Help Coding A Downloader? Fragma 9 3,407 08-25-2011, 06:10 PM
Last Post: LiveModz

Forum Jump:


Users browsing this thread: 1 Guest(s)