Dev Direct Solution Center

For more information and to buy this product...

Telerik RadUpload for ASP.NET AJAX

  For a copy of the sample project please click here to download and install the product evaluation.

Introduction

You can achieve your goal by using RadUpload for ASP.NET AJAX. For details on the matter please take a look at these online examples. http://www.telerik.com/demos/aspnet/prometheus/Upload/Examples/CustomProgress/DefaultCS.aspx http://www.telerik.com/demos/aspnet/prometheus/Upload/Examples/ProgressTemplate/DefaultCS.aspx

Detail

Monitoring Custom Progress

RadProgressArea is designed to provide the ability to monitor the progress of any measurable process.

In order to monitor a custom progress you need to put a RadProgressArea and RadProgressManager on your page.

Then using the RadProgressContext class you send the progress couters to RadProgressManager

If you want to update the elements of the default progress template you should use the following keys in the progress 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.
C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using Telerik.Web.UI.Upload;

namespace Telerik.Web.Examples.Upload.CustomProgress
{
    public partial class DefaultCS : Telerik.QuickStart.XhtmlPage
    {    
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                //Do not display SelectedFilesCount progress indicator.
                RadProgressArea1.ProgressIndicators &= ~ProgressIndicators.SelectedFilesCount;

                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";
            }

        }

        protected void buttonSubmit_Click(object sender, System.EventArgs e)
        {
            UploadedFile file = RadUploadContext.Current.UploadedFiles[inputFile.UniqueID];

            if(!Object.Equals(file, null))
            {
                LooongMethodWhichUpdatesTheProgressContext(file);
            }
        }

        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);
            }
        }    
    }
}
Visit Telerik Inc. for more information and more samples.