Total progress (of all files)

Last post 07-25-2009, 1:15 AM by cutechat. 6 replies.
Sort Posts: Previous Next
  •  04-17-2009, 11:11 AM 51210

    Total progress (of all files)

    Hi,
     
    Is there a way of displaying the total progress of all files?
     
    I see how I can customise the display of the progress area - but how can I show, for example, a progress percentage of ALL the files selected for upload - i.e. (total number of KB sent so far for all files / total bytes of all files) * 100
     
    Many thanks
     
    db
  •  04-17-2009, 2:25 PM 51223 in reply to 51210

    Re: Total progress (of all files)

    Hi,
     
    We will not provide buindin function for that.
     
    But we will make a sample for that soon.
     
    Regards,
    Terry
     
  •  04-20-2009, 12:14 AM 51241 in reply to 51223

    Re: Total progress (of all files)

    Hi,
     
    This is a sample for total progress info:
     
     
    1. <%@ Page Language="C#" Title="Total Progress" %>  
    2. <%@ Import Namespace="CuteWebUI" %>  
    3. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    5.   
    6. <script runat="server">  
    7.   
    8.     void InsertMsg(string msg)   
    9.     {   
    10.         ListBoxEvents.Items.Insert(0, msg);   
    11.         ListBoxEvents.SelectedIndex = 0;   
    12.     }   
    13.     protected void UploadAttachments1_AttachmentAdded(object sender, AttachmentItemEventArgs args)   
    14.     {   
    15.         InsertMsg("Added.." + args.Item.FileName);   
    16.     }   
    17.   
    18. </script>  
    19.   
    20. <html xmlns="http://www.w3.org/1999/xhtml">  
    21. <head id="Head1" runat="server">  
    22. </head>  
    23. <body>  
    24.     <form id="Form1" runat="server">  
    25.         <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" OnAttachmentAdded="UploadAttachments1_AttachmentAdded">  
    26.         </CuteWebUI:UploadAttachments>  
    27.         <div id='progressInfo' style="display:none;font-size:18px;color:DarkRed"></div>  
    28.         <br />  
    29.         <div>  
    30.             Server Trace:   
    31.             <br />  
    32.             <asp:ListBox runat="server" ID="ListBoxEvents" Width="800"></asp:ListBox>  
    33.         </div>  
    34.     </form>  
    35.     <script type="text/javascript">  
    36.     function ToFixed(num) {   
    37.         if (num > 100)   
    38.             return Math.round(num);   
    39.         if (num > 10)   
    40.             return num.toFixed(1);   
    41.         return num.toFixed(2);   
    42.     }   
    43.     function FormatSize(bytecount) {   
    44.         var str = bytecount + ' B';   
    45.         if (Number(bytecount) >= 2048) { str = ToFixed(bytecount / 1024) + ' KB'; }   
    46.         if (Number(bytecount) >= 2097152) { str = ToFixed(bytecount / 1048576) + ' MB'; }   
    47.         if (Number(bytecount) >= 2147483648) { str = ToFixed(bytecount / 1073741824) + ' GB'; }   
    48.         return str;   
    49.     }   
    50.        
    51.     var progressInfo=document.getElementById("progressInfo");   
    52.     var hasStarted=false;   
    53.     var startTime=0;   
    54.     var fullSize=0;   
    55.     var finishSize=0;   
    56.     var queueSize=0;   
    57.     var filecount=0;   
    58.     function CuteWebUI_AjaxUploader_OnStart()   
    59.     {   
    60.         if(hasStarted)return;   
    61.         hasStarted=true;   
    62.         startTime=new Date().getTime();   
    63.         progressInfo.innerHTML="Start upload";   
    64.         progressInfo.style.display="";   
    65.     }   
    66.     function CuteWebUI_AjaxUploader_OnStop()   
    67.     {   
    68.         hasStarted=false;   
    69.         progressInfo.style.display="none";   
    70.     }   
    71.     function CuteWebUI_AjaxUploader_OnPostback()   
    72.     {   
    73.         hasStarted=false;   
    74.         progressInfo.style.display="none";   
    75.     }   
    76.     function CuteWebUI_AjaxUploader_OnQueueUI(list)   
    77.     {   
    78.         filecount=list.length;   
    79.         fullSize=0;   
    80.         finishSize=0;   
    81.         queueSize=0;   
    82.         for(var i=0;i<list.length;i++)   
    83.         {   
    84.             var size=list[ i ].FileSize;    //or -1 if iframe mode   
    85.             var stat=list[ i ].Status;   
    86.             fullSize+=size;   
    87.             if(stat=="Finish")   
    88.                 finishSize+=size;   
    89.             if(stat=="Queue")   
    90.                 queueSize+=size;   
    91.         }   
    92.         return true;   
    93.     }   
    94.     function CuteWebUI_AjaxUploader_OnProgress(enable,filename,begintime,uploadedsize,totalsize)   
    95.     {   
    96.         if(fullSize<0)   
    97.         {   
    98.             progressInfo.innerHTML="Unable to calculate total progress for iframe mode";   
    99.             return true;   
    100.         }   
    101.            
    102.         if(!enable)   
    103.             return;   
    104.         if(!totalsize)   
    105.             return;   
    106.   
    107.         var size1=finishSize+uploadedsize;   
    108.         var size2=queueSize+totalsize-uploadedsize;   
    109.         var size3=size1+size2;   
    110.         var seconds=(new Date().getTime()-startTime)/1000;   
    111.         var speed=size1/seconds;   
    112.         var timeleft=size2/speed;   
    113.   
    114.         progressInfo.innerHTML="Uploading "+filecount+" files. "+FormatSize(size1)+" of "+FormatSize(size3)+" at "+FormatSize(Math.round(speed))+"/s; "+Math.round(timeleft)+" seconds remaining ";   
    115.         //return false;   
    116.     }   
    117.     </script>  
    118.   
    119. </body>  
    120. </html>  
     
    Regards,
    Terry
     
  •  04-21-2009, 4:20 AM 51302 in reply to 51241

    Re: Total progress (of all files)

    Thank for the sample - there seems to be a problem with the total size estimate though, I'm uploading the following two files:
     
     
     
    and the script is saying they are over 1.4GB...
     
     
     
    Many thanks,
     
    db
  •  04-21-2009, 9:21 AM 51312 in reply to 51302

    Re: Total progress (of all files)

    Oh, That's a bug because the number is not reset to zero.
     
    The code is updated, please copy it and test again.
     
    Regards,
    Terry
     
  •  07-23-2009, 12:42 PM 54228 in reply to 51312

    Re: Total progress (of all files)

    Hi,
     
    Thank you for the updated sample.
     
    Is there a better fallback for when the control renders in IFrame mode (i.e. when total file progress is not available)? - i.e. show just the progress of the current file and the number of remaining files?
     
    Many thanks
     
    dan
     
     
  •  07-25-2009, 1:15 AM 54272 in reply to 54228

    Re: Total progress (of all files)

    Hi,
     
    If list[ i ].FileSize; is -1 , all files will be -1
     
    So you can save this condition to a flag , and change the display string in the OnProgress event.
     
    Regards,
    Terry
View as RSS news feed in XML