Vb.net 文件上传的上传进度条
我有这个代码,如何将进度条合并到其中Vb.net 文件上传的上传进度条,vb.net,Vb.net,我有这个代码,如何将进度条合并到其中 Private Sub btn_upload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_upload.Click Dim filePath As String = lbl_file.Text Dim slashPosition As Integer = filePath.LastIndexOf("\") Dim fil
Private Sub btn_upload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_upload.Click
Dim filePath As String = lbl_file.Text
Dim slashPosition As Integer = filePath.LastIndexOf("\")
Dim filenameOnly As String = filePath.Substring(slashPosition + 1)
Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://.com/public_html/windows/" & filenameOnly), System.Net.FtpWebRequest)
request.Credentials = New System.Net.NetworkCredential("", "")
request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Dim path As String = lbl_file.Text
Dim file() As Byte = System.IO.File.ReadAllBytes(path)
Dim strz As System.IO.Stream = request.GetRequestStream()
strz.Write(file, 0, file.Length)
strz.Close()
strz.Dispose()
MsgBox(path)
End Sub
与一次读取所有字节然后一次上载它们不同,您可以以设置大小的块读取和写入字节,然后根据总字节计算百分比。作为一个简单的例子,下面是如何更新每个发送的KB的上传进度
For offset as Integer = 0 to File.Length Step 1024
ProgressBar1.Value = CType(offset * ProgressBar1.Maximum / File.Length, Integer)
Dim chunkSize as Integer = File.Length - offset - 1
If chunkSize > 1024 Then chunkSize = 1024
strz.Write(file, offset, chunkSize)
Next
ProgressBar1.Value = ProgressBar1.Maximum
与一次读取所有字节然后一次上载它们不同,您可以以设置大小的块读取和写入字节,然后根据总字节计算百分比。作为一个简单的例子,下面是如何更新每个发送的KB的上传进度
For offset as Integer = 0 to File.Length Step 1024
ProgressBar1.Value = CType(offset * ProgressBar1.Maximum / File.Length, Integer)
Dim chunkSize as Integer = File.Length - offset - 1
If chunkSize > 1024 Then chunkSize = 1024
strz.Write(file, offset, chunkSize)
Next
ProgressBar1.Value = ProgressBar1.Maximum
啊,现在可以了,我该如何让它定期更新到我表格上的进度条中呢?为所有的帮助干杯@HarryBeasant我将示例中的标签更改为ProgressBar控件。如果这回答了你的问题,你介意接受它作为答案吗?@HarryBeaant-使用BackgroundWorker在progressbarAh works上显示实时状态。现在,我如何让它定期更新到我表格上的进度条中?为所有的帮助干杯@HarryBeasant我将示例中的标签更改为ProgressBar控件。如果这回答了你的问题,你介意接受它作为答案吗?@HarryBeaant-使用BackgroundWorker在进度条上显示实时状态