Solved

Upload progress bar

Posted on 2004-03-23
1
986 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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