Visual Basic e.TotalBytesToReceive始终给出-1 [英] Visual basic e.TotalBytesToReceive gives always -1

查看:125
本文介绍了Visual Basic e.TotalBytesToReceive始终给出-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已经制作了一个可以工作的FTP下载器,但是我想在下载文件之前先获取文件大小.我使用e.TotalBytesToReceive,但它始终为我提供-1的值,而e.bytesrecived的效果很好. (我将使用这两个值来制作进度条).这是我的代码:


Hi I have made a working FTP downloader, but I want to get file size before downloading the file. I use e.TotalBytesToReceive but it always gives me the value of -1, while e.bytesrecived works very good . (I will use these 2 values to make a progressbar). Here is my code:


Imports System.Net

Public Class Download

    WithEvents WebIllyria As New Net.WebClient 'WithEvents WebClient As New Net.WebClient

    Private Sub Download_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Uri As New Uri("ftp://illyriapatch@ftp.drivehq.com/illyria.exe")
        Try

            WebIllyria.Credentials = New Net.NetworkCredential("username", "password")
            WebIllyria.DownloadFileAsync(Uri, "c:\illyria.exe")

        Catch ex As Exception
           
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub WebIllyria_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebIllyria.DownloadProgressChanged
        ProgressDownload.Value = e.ProgressPercentage
        Label4.Text = e.TotalBytesToReceive
        Label3.Text = e.BytesReceived
        Label2.Text = e.ProgressPercentage & "%"
        If ProgressDownload.Value = 100 Then
            MessageBox.Show("Download Completed!!")
            Label2.Text = "..."
        End If
    End Sub
End Class

推荐答案

我认为 http://social.msdn. microsoft.com/forums/en-us/netfxnetcom/thread/F5FE49AA-65BA-4EF9-A3B9-5EE6A2242829 [
I think that http://social.msdn.microsoft.com/forums/en-us/netfxnetcom/thread/F5FE49AA-65BA-4EF9-A3B9-5EE6A2242829[^] may answer your question.


这篇关于Visual Basic e.TotalBytesToReceive始终给出-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆