|
-
Apr 25th, 2004, 04:00 PM
#1
Thread Starter
Lively Member
System.Net.Webclient
What's the proper way to download a file off the Internet? I could use WebRequest or WebClient, which one am I better off using?
I want to build a progress bar for my downloader, so how can I do that? I tried using webclient.OpenRead but the stream I got back I couldn't seek through, so how the hell do I know how big a file off the Internet is supposed to be?
Can't really implement a progress bar until I know that now, can I?
Here's my crappy ass code that doesn't work.
VB Code:
Public Sub DownloadFile(ByVal fileUrl As String, ByVal saveTo As String, ByVal progress As ProgressBar)
Dim client As New WebClient
Dim myStream As Stream = client.OpenRead(fileUrl)
progress.Visible = True
progress.Maximum = CType(myStream.Length, Integer)
'Dim sr As New StreamReader(myStream)
Dim r As New BinaryReader(myStream)
Dim fs As New FileStream(saveTo, FileMode.Create)
Dim w As New BinaryWriter(fs)
Dim i As Long, res As Byte, locate As Integer = 0
For i = 0 To myStream.Length
res = r.ReadByte()
w.Write(res)
progress.Value += 1
Next i
progress.Visible = False
progress.Value = 0
w.Close()
fs.Close()
r.Close()
End Sub
-
Apr 25th, 2004, 04:04 PM
#2
try this thread in the code bank ... retrieve image size+download with progressbar ( from the web )
it's a sample i made for downloading images with a progressbar , but can be used / modified for downloading files also.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Apr 26th, 2004, 01:33 AM
#3
Thread Starter
Lively Member
Thanks for the reply, that did the trick.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|