0

I know there are many similar questions but I am kind of restricted in many terms for this case. I am using SharpBox to upload files to Dropbox and in order to create a progress bar visible to user, I am using a static method where SharpBox returns the percenatge. It is all fine but I need to return this information to the aspx page or javascript somehow.

I cannot add a parameter to the method. I could remove the static from the method however it does still gives an exception null on the label which is quite strange (probably because the method fires from SharpBox dynamically).

So the method UploadDownloadProgress is the part where I have problems with.

 public class docUpload
 {

    static public void Doc_Upload()
    {
        dropBoxStorage.UploadFile(stream, filename, entry, UploadDownloadProgress);
    } 

    static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
    {

        // I need the e.PercentageProgress on aspx page
        System.Diagnostics.Debug.WriteLine(e.PercentageProgress);

        // This wont work since it is a static method
        myLabel.Text = e.PercentageProgress.ToString();

        e.Cancel = false;
    }
}

I need the e.PercentageProgress in the label. I also alternatively tried to call javascript without success. Could you suggest any other alternatives?

Jorge.Methew
  • 75
  • 1
  • 10

1 Answers1

0

Try something like this:

public class docUpload
{
    static public void Doc_Upload()
    {
        dropBoxStorage.UploadFile(stream, filename, entry, ProgressInformer.UploadDownloadProgress);
    } 
}

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
  • Can't call the method inside docUpload like this ProgressInformer.UploadDownloadProgress – Jorge.Methew Apr 24 '16 at 17:39
  • Try using a lambda expression to do it like this (e, s) => { ProgressInformer.UploadDownloadProgress(e, s) }. I am sorry about the imaginitive solution as I cannot get to replicate the exact code in my local VS to give you definite way. – Benison Sam Apr 24 '16 at 17:48
  • Even if i get it work there, the UploadDownloadProgress fires from the SharpBox automatically few times and Progress does not update for the label on the aspx page. – Jorge.Methew Apr 24 '16 at 18:23