RadUpload for ASP.NET

Custom Progress Monitoring Send comments on this topic.
Progress Monitoring > Custom Progress Monitoring

Glossary Item Box

RadProgressArea was designed to provide the ability to monitor the progress of file uploads or any other measurable process.

If you want to monitor only custom progress, you need to register RadUploadProgressHandler and set RadProgressManager's SuppressMissingHttpModuleError property to true in order to the avoid error messages from it.

If you want to update the elements of the default progress template you should use the following keys in the RadProgressContext.Current HashTable:

  • PrimaryTotal - the maximum value of the primary progress indicators. By default RadProgressArea displays here the request size.
  • PrimaryValue - the current value of the primary progress indicators. By default RadProgressArea displays here the uploaded bytes count.
  • PrimaryPercent - the percentage of PrimaryValue from PrimaryTotal.
  • SecondaryTotal - the maximum value of the secondary progress indicators. By default RadProgressArea displays here the number of the selected files on the page.
  • SecondaryValue - the current value of the secondary progress indicators. By default RadProgressArea displays here the count of the complete uploaded files.
  • SecondaryPercent - the percentage of SecondaryValue from SecondaryTotal
  • CurrentOperationText - the description of the current operation. By default RadProgressArea displays here the name of the currently uploaded file.
  • TimeEstimated - the estimated time until the operation completes.
  • TimeElapsed - the elapsed time from the beginning of the operation.
  • Speed - The execution speed of the process. By default RadProgressArea displays here the upload speed.

If you set some of these properties before upload they will not be used for file upload monitoring.

Example:

The following example demonstrates how to monitor both file upload and custom process using one RadProgressArea:

<input runat="server" id="File1" type="file" />
<rad:radprogressmanager id="RadProgressManager1" runat="server" />
<rad:radprogressarea id="RadProgressArea1" runat="server" />
<asp:button id="Button1" runat="server" text="Submit" />

VB.NET

Private Sub LooongMethodWhichUpdatesTheProgressContext(file as UploadedFile)
 Dim total As Integer = 100

 Dim progress As Telerik.WebControls.RadProgressContext = RadProgressContext.Current

 For i As Integer = 0 To total - 1
  'Set the values of the secondary progress
  progress("SecondaryTotal") = total.ToString()
  progress("SecondaryValue") = i.ToString()
  progress("SecondaryPercent") = i.ToString()
  progress("CurrentOperationText") = file.GetName + " is being processed..."

  If Not Response.IsClientConnected Then
   'Cancel button was clicked or the browser was closed, so stop processing
   Exit For
  End If

  'Stall the current thread for 0.05 seconds to simulate server-side processing
  System.Threading.Thread.Sleep(50)
 Next
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim file As UploadedFile = RadUploadContext.Current.UploadedFiles(File1.UniqueID)
 'Process the uploaded file
 If Not file Is Nothing Then
  LooongMethodWhichUpdatesTheProgressContext(file)
 End If
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 If Not IsPostBack Then
  'Do not display SelectedFilesCount progress indicator.
  RadProgressArea1.ProgressIndicators = ProgressIndicators.CurrentFileName Or _
   ProgressIndicators.FilesCount Or _
   ProgressIndicators.FilesCountBar Or _
   ProgressIndicators.FilesCountPercent Or _
   ProgressIndicators.RequestSize Or _
   ProgressIndicators.TimeElapsed Or _
   ProgressIndicators.TimeEstimated Or _
   ProgressIndicators.TotalProgress Or _
   ProgressIndicators.TotalProgressBar Or _
   ProgressIndicators.TotalProgressPercent Or _
   ProgressIndicators.TransferSpeed

  RadProgressArea1.Localization("UploadedFiles") = "Processed "
  RadProgressArea1.Localization("TotalFiles") = ""
  RadProgressArea1.Localization("CurrentFileName") = "File: "

  Dim progress As RadProgressContext = RadProgressContext.Current
  'Prevent the secondary progress from appearing when the file is uploaded (FileCount etc.)
  progress("SecondaryTotal") = 0
  progress("SecondaryValue") = 0
  progress("SecondaryPercent") = 0
 End If
End Sub

C#

private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file)
{
   const int total = 100;

   RadProgressContext progress = RadProgressContext.Current;
   for (int i=0; i<total; i++)
   {
      progress["SecondaryTotal"] = total.ToString();
      progress["SecondaryValue"] = i.ToString();
      progress["SecondaryPercent"] = i.ToString();
      progress["CurrentOperationText"] = file.GetName() + " is being processed...";

      if (!Response.IsClientConnected)
      {
          //Cancel button was clicked or the browser was closed, so stop processing
          break;
      }

      //Stall the current thread for 0.1 seconds
      System.Threading.Thread.Sleep(100);
   }
}

private void Button1_Click(object sender, System.EventArgs e)
{
   UploadedFile file = RadUploadContext.Current.UploadedFiles[File1.UniqueID];
   if (file != null)
   {

      LooongMethodWhichUpdatesTheProgressContext(file);
   }
}

protected void Page_Load(Object sender, System.EventArgs e)
{
   if (!IsPostBack)
   {
      //Do not display SelectedFilesCount progress indicator.
      RadProgressArea1.ProgressIndicators = ProgressIndicators.CurrentFileName |
         ProgressIndicators.FilesCount |
         ProgressIndicators.FilesCountBar |
         ProgressIndicators.FilesCountPercent |
         ProgressIndicators.RequestSize |
         ProgressIndicators.TimeElapsed |
         ProgressIndicators.TimeEstimated |
         ProgressIndicators.TotalProgress |
         ProgressIndicators.TotalProgressBar |
         ProgressIndicators.TotalProgressPercent |
         ProgressIndicators.TransferSpeed;

      RadProgressArea1.Localization["UploadedFiles"] = "Processed ";
      RadProgressArea1.Localization["TotalFiles"] = "";
      RadProgressArea1.Localization["CurrentFileName"] = "File: ";

      RadProgressContext progress = RadProgressContext.Current;
      //Prevent the secondary progress from appearing when the file is uploaded (FileCount etc.)
      progress["SecondaryTotal"] = "0";
      progress["SecondaryValue"] = "0";
      progress["SecondaryPercent"] = "0";
   }
}