Solved

Upload progress bar

Posted on 2004-03-23
1
976 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

12 Experts available now in Live!

Get 1:1 Help Now