Support Forums
[TUT]Make an Advanced File Downloader - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [TUT]Make an Advanced File Downloader (/showthread.php?tid=16224)



[TUT]Make an Advanced File Downloader - ThePrinCe - 02-17-2011

Advanced File Downloader


Ok Heres the TUT.
1.Make a new project named Advanved file downloader.
2.Add 2 buttons, a textbox, and a progress bar.
3.Name one button "Save As",and the other "Download"
4.Double click Save As and paste this code.
Code:
Dim save AsNew SaveFileDialog
save.Title = "Advanced Downloader"
save.ShowDialog()
TextBox1.Text = save.FileName

5.Double click Download and paste this code.
Code:
httpclient = New WebClient
Dim sourceurl = ("http://failblog.files.**.com/2009/12/epic-fail-7-11-fail.jpg")
Dim filedir = TextBox1.Text
ProgressBar1.Minimum = "0"
ProgressBar1.Maximum = "100"
Try
httpclient.DownloadFileAsync(New Uri(sourceurl), (filedir))
Catch ex As Exception
'do nothing
EndTry

6.Now after the "end sub" of that code paste:
Code:
PrivateSub httpclient_DownloadProgressChanged(ByVal sender AsObject, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
EndSub

Note: This is the download percent
7.Now above PublicClass Form1 paste :

Code:
Imports System.Net

8.No under public class form 1 paste:
Code:
PrivateWithEvents httpclient As WebClient

The CODE :
Code:
Imports System.Net
Public Class Form1
    Dim save As New SaveFileDialog
    Private WithEvents httpclient As WebClient
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  httpclient = New WebClient
  Dim sourceurl = ("http://failblog.files.**.com/2009/12/epic-fail-7-11-fail.jpg")
  Dim filedir = TextBox1.Text
  ProgressBar1.Minimum = "0"
  ProgressBar1.Maximum = "100"
  Try
    httpclient.DownloadFileAsync(New Uri(sourceurl), (filedir))
  Catch ex As Exception
    'do nothing
  End Try
    End Sub
    Private Sub httpclient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
  ProgressBar1.Value = e.ProgressPercentage
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  save.Title = "Advanced Downloader"
  save.ShowDialog()
  TextBox1.Text = save.FileName
    End Sub
End Class

thank's to jommla for fixing it Smile.