Network.DownloadFile with progressbar

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

How can i use
Code: Select all
 My.Computer.Network.DownloadFile
with a progressbar to show its progress in downloading ?
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

You can't.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

MrAksel wrote:
You can't.
Is there other download methods where i can use it then ?
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Code: Select all
Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://www.server.com/file.txt"), HttpWebRequest)
Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Dim stream As Stream = res.GetResponseStream()

Dim file As FileStream = New FileStream("C:\file.txt", FileMode.Create, FileAccess.Write)

ProgressBar1.Maximum = res.ContentLength
Dim Buffer As Byte() = New Byte(4095) {}
Dim count As Integer = 0
Dim max As Integer = res.ContentLength

Do While(count < max)
   Dim read = stream.Read(buffer, 0, 4096)
   file.Write(buffer, 0, read)
   count += read
   ProgressBar1.Value = count
   Application.DoEvents()
Loop

file.Close()
stream.Close()
res.Close()
I think this would work. I haven't tested it.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
4 posts Page 1 of 1
Return to “Coding Help & Support”