Solved

Upload progress bar

Posted on 2004-03-23
1
980 Views
Last Modified: 2012-06-22
We have developed an application using VB.Net. Application is uploading a file with the help of Webclient Upload. We need to show upload progress using a progress bar. Please give us some ideas on how this can be implemented?
0
Comment
Question by:zakali
1 Comment
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 10657335
You cannot have the progress bar during upload because you don't know the size of downloaded portion
Yoiu have 2 choices
1.SHow infinite process - just to let user know that something is going on

For example update progress bar on a timer (you have to do it in a different thread)


2.Download block and then update progress bar. Here is an example for copy file. You will get the idea
'add Button1 and ProgressBar1

Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'if file exists it will overwrite it
        Me.FileCopyProgress("F:\Handheld\Friend\Data\HHPalm\CremosaBackEnd.mdb", "c:\a\cbe.mdb)
        MsgBox("Success")
    End Sub

    Private Sub FileCopyProgress(ByVal Filelocation As String, ByVal CopyToDestination As String)
        Dim ReturnValue As Boolean
        Dim TaskProgress As Integer 'contains the total value that this task takes in the progress bar
        Dim FileSize As Integer ' contains the size of the file wanting to be copied in bytes as integer
        Dim FileStreamCopyFrom As FileStream
        Dim FileStreamCopyTo As FileStream
        Dim loops As Integer
        Dim i As Integer
        Dim ByteSize As Integer
        Dim ExpectedLoops As Integer
        Dim IsWholeNumber As Integer

        IsWholeNumber = 1
        TaskProgress = ProgressBar1.Maximum - ProgressBar1.Minimum 'tells us how many 'bits' of the status bar this task takes up
        ByteSize = TaskProgress
        FileStreamCopyFrom = File.Open(Filelocation, FileMode.Open, FileAccess.Read)
        FileStreamCopyTo = File.Open(CopyToDestination, FileMode.OpenOrCreate, FileAccess.Write)
        FileSize = FileStreamCopyFrom.Length

        'We now want to find a number that can divide the total filesize into a whole number (leaving no reamainder)
        'the best way to do this is to use the TaskProgress value and work down to find this number
        Do
            IsWholeNumber = FileSize Mod (ByteSize + 1)
            If Not IsWholeNumber = 0 Then
                ByteSize = ByteSize - 1
            End If
        Loop While Not IsWholeNumber = 0

        Dim MyByte(ByteSize) As Byte 'declare MyByte as byte array using our new value

        ExpectedLoops = System.Math.Floor(FileSize / (ByteSize + 1)) 'Stores how many loops we expect to see by rounding down the result of div.

        If Not FileSize Mod (ByteSize + 1) = 0 Then
            ExpectedLoops = ExpectedLoops + 1
        End If

        i = FileStreamCopyFrom.Read(MyByte, 0, ByteSize + 1) '1024reads data in 1kb at a time to b2

        loops = 0  'set loops = 0 as we have not looped yet.
        Do
            loops += 1
            FileStreamCopyTo.Write(MyByte, 0, ByteSize + 1)
            i = FileStreamCopyFrom.Read(MyByte, 0, ByteSize + 1)
            'increase the progress bar
            ProgressBar1.Value = ProgressBar1.Minimum + ((TaskProgress / ExpectedLoops) * loops)
        Loop Until i = 0
        FileStreamCopyFrom.Close() 'close the filestreams
        FileStreamCopyTo.Close()   'close the filestreams
    End Sub

End Class

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
Help with WinAPI Signatures in VB.NET for SetWindowSubclass 2 34
coded character set iptc field within a jpeg 1 69
SQL Exceptions 3 38
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now