Last post Aug 29, 2016 10:17 AM by Ritesh Singh
Aug 27, 2016 11:30 PM|tftdrd60|LINK
I have written a routine to upload a file to my website but really need a progress label - even a text representation of how far the file has uploaded.
I am using ASP.NET with a codebehind in VB.NET
The code I am using for FTP UPLOAD is
'Create FTP Request.
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(ftp & ftpFolder & fileName), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
'Enter FTP Server credentials.
request.Credentials = New NetworkCredential("username", "password")
request.ContentLength = fileBytes.Length
request.UsePassive = True
request.UseBinary = True
request.ServicePoint.ConnectionLimit = fileBytes.Length
request.EnableSsl = False
lblMessage.Text = "PLEASE WAIT - UPLOADING"""
Using requestStream As Stream = request.GetRequestStream()
requestStream.Write(fileBytes, 0, fileBytes.Length)
Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
lblMessage.Text = fileName & " uploaded.<br />"
Catch ex As WebException
lblMessage.Text = ex.ToString
Someone (Brother tells me this is synchronous and can not report back a progress - so how can I change this code to report back the progress of the uploaded file in the write phase.
Thank you in advance for any feedback.
Aug 29, 2016 06:00 AM|sreejukg|LINK
Aug 29, 2016 10:01 AM|Deepak Panchal|LINK
I try to find regarding your issue and I found a common code block for progress bar in more then one sources.
following is the code block that you can try to integrate with your code.
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)
ProgressBar1.Value = ProgressBar1.Maximum
I found the above mentioned code in following links.
Ftp Upload Progressbar vb.net
Upload Progress Bar for file upload
Aug 29, 2016 10:17 AM|Ritesh Singh|LINK
but my file is uploaded on anchor tag click that is asynchronous call ... that is the problem