This is a migrated thread and some comments may be shown as answers.

Beginner RadUpload Q: detecting finished uploads

3 Answers 66 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
jtc
Top achievements
Rank 1
jtc asked on 22 Sep 2010, 04:29 PM
Hi everyone,

I have a simple site that I am working on, and have a page which uses an asp.net MasterPage and a RadAjaxPanel to hold the main content of the page.  Within this are several regular asp.Panels. 

The idea is to have a single sign-up page, showing different asp.Panel instances to indicate the step in the process.  This works fine.

Near the end is the facility to upload an image or video, and I am using RadUpload (with the RadProgressManager).  Again, this works fine, BUT here is where my newbie-to-Telerik status lets me down.

I'm not totally clear on how I know when a file has finished uploading.  I expected there to be some kind of event to which I could place some code, but other than using something like:

if (Page.IsPostBack)
{
   // perhaps we've uploaded a file?
   if (RadUpload1.UploadedFiles.Count>0)
   {
        panSampleTestUploadSelect.Visible = false;
        panSampleTestUploadComplete.Visible = true;
   }
}

...I am not sure what else to do.  I think I must be misunderstanding something here.  The other bit of code I am using is an asp.Button to trigger the upload (button has been explicitly set to PostBack):

protected void CmdUpload_Click(object sender, EventArgs e)
{
    if (RadUpload1.UploadedFiles.Count > 0)
    {
        System.Threading.Thread.Sleep(3000);
    }
}

I'm not even clear why I this thread should sleep for 3 seconds - can anyone explain?  Incidentally, I copied this from an example in the online help.

OK, thanks for any help!

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 23 Sep 2010, 04:11 PM
I'm assuming your question is how you can determine if the uploaded succeeded or not when the upload button is pressed. If so, in your upload button you check that UploadFiles collection and determine if it contains any uploaded files. Meaning the upload succeeded, otherwise it will contain no items, meaning the the upload failed. If it succeeded, you can toggle your panel visibility.

So this is what your upload button would look like:

protected void CmdUpload_Click(object sender, EventArgs e)
{
    // check if file was uploaded
   if (RadUpload1.UploadedFiles.Count>0)
   {
        panSampleTestUploadSelect.Visible = false;
        panSampleTestUploadComplete.Visible = true;
   }
}

To explain the Thread part of the code that you posted here. In the demo, it's there to simulate a long process, it's not needed in your code.

I hope that helps.
0
jtc
Top achievements
Rank 1
answered on 24 Sep 2010, 08:48 AM
Thanks, Cori.  Your explanation has helped, but I'm still not totally clear on the 'timeline' of an upload.

You're saying that when I click on the CmdUpload button (in my example) I can check the UploadedFiles collection to see if the files are uploaded.  But, say I am uploading a 20Mb file - that's probably going to take at least a few seconds if not minutes.  So, looking at the Click event, I'd enter into that immediately, check the UploadedFiles, but as my large file wouldn't have been uploaded at this point (too early) then it would show no uploaded files.  

I had expected some kind of event which would fire on the completion of an upload, but I can't see any.  

Short of looping in the click event (with a thread.sleep between iterations) and polling for completion, I can't see how this works.

I am sure I'm being a bit stupid here and I'm getting confused over small details, but here's what I'd LIKE to happen:

CmdUpload_Click event fires
...upload begins
: (progress bar updates)
...on successful completion of upload, I flip to the next panel in the sequence, showing a confirmation of the upload.

Thanks.

0
Cori
Top achievements
Rank 2
answered on 24 Sep 2010, 06:24 PM
I don't think you understand how a web page works. The click event does not get raised while the file is uploading, since the page only posts back once the file has been uploaded. Thus, the click event will always know if the file was uploaded or not.

Is this not the case in your situation? Are you using the standard RadUpload control or  the RadAsyncUpload control?
Tags
Upload (Obsolete)
Asked by
jtc
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
jtc
Top achievements
Rank 1
Share this question
or