Prova con questa:
codice:
Dim str As Stream = Nothing
Dim fstr As FileStream = Nothing
Dim DownloadedBytes as integer
Try
Dim wr As HttpWebRequest = CType(WebRequest.Create(Indirizzo), HttpWebRequest)
Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
str = ws.GetResponseStream()
Dim inBuf(4096) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0
fstr = New FileStream(PercorsoSalvataggio, FileMode.OpenOrCreate, FileAccess.Write)
While bytesToRead > 0
Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
Else
fstr.Write(inBuf, 0, n)
End If
DownloadedBytes += n
End While
Catch ex As Exception
DownloadFile = ""
MessageBox.Show("Errore", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If str IsNot Nothing Then str.Close()
If fstr IsNot Nothing Then fstr.Close()
End Try
Nel ciclo While gli metti:
codice:
If ((DownloadedBytes / 4096) / FileLenght) * 100 <= 100 Then
PB.Value = CInt(((DownloadedBytes / 4096) / FileLenght) * 100)
Else
PB.Value = PB.Maximum
End If
Recuperi la dimensione del file dall'Header del HttpWebResponse oppure da ws.ContentLenght
Fammi sapere.