2

I am trying to show user a progress bar during the uploadFile. I can get the percentage in back end through the method below, however I cannot manage to print the percentage returned by e.PercentageProgress to display to the user.

  static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
  {
        // Need to show this on a label or return to front end somehow
        System.Diagnostics.Debug.WriteLine(e.PercentageProgress);            

        e.Cancel = false;
  }

The question is how can I get the e.PercentageProgress to show on an aspx page or get it to use in javascript?

Jorge.Methew
  • 75
  • 1
  • 10
  • This does not seem to be so easy to achieve. I had to modify my solution and upload the file first on the server (where I can easily show a progress bar) and then upload to dropbox. This will just run in the background so user does not need to be informed about it and will complete request regardless of user staying or leaving the site (web-method). Another advantage was the major decrease for the upload time. – Jorge.Methew May 23 '16 at 15:07

1 Answers1

0

Try something like this:

public class ProgressInformer {

    public static string Progress = "0";

    static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
    {

        // print a dot           
        System.Diagnostics.Debug.WriteLine(e.PercentageProgress);

        // Need to show this on a label or return to front end somehow
        ProgressInformer.Progress = e.PercentageProgress.ToString();

        e.Cancel = false;
    }
}

Now since you are setting the static variable with value you can access it from somewhere else. Then you can use that value to echo on the front-end using some method or service. Possibly like this:

public string EchoToFrontEnd()
{
    return ProgressInformer.Progress;
}

Limitation: If this works for you still this solution is not thread safe. That means, you cannot echo progress for multiple downloads. You'll have to work with a single download at a time.

Hope this helps...!

Benison Sam
  • 2,755
  • 7
  • 30
  • 40
  • The thing is SharpBox fires the method automatically few times. Even if I set the Progress, I need to get the data exactly when the UploadDownloadProgress method gets fired. I am trying something like this now and the value never changes:perc.Text = docUpload.Progress.ToString(); – Jorge.Methew Apr 24 '16 at 17:34
  • So it actually seems that I need to manage getting the percentage to front end within the method UploadDownloadProgress – Jorge.Methew Apr 24 '16 at 17:39