Solved

Upload progress bar

Posted on 2004-03-23
1
985 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

737 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