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

UploadFinished event not firing on some errors

2 Answers 76 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 2
Stephen asked on 24 Jan 2012, 09:23 PM
Hello,

I'm using the RadUpload programmatically to upload from a stream with the Q3 2011 SP1(2011.3.1220.1040) release.

I'm finding that I don't get an UploadFinished event if the RadUpload returns the "handler not found" error(which I purposely messed up to test error handling) but I do get it if I get an actual FileUpload error.
The problem is that I have some important code in the UploadFinished event to turn of the BusyIndicator and continue running instead of looking "hung".

I have Debug.WriteLine's in all the events and if I have a bad handler reference I get:
 - UploadStarted
 - FileUploadStarting
 - FileUploadFailed
and the BusyIndicator never goes away.

If I have an error uploading the file I get:
 - UploadStarted
 - FileUploadStarting
 - FileUploadFailed
 - UploadFinished

I can easily fix a bad handler but my concern is what other errors behave this way and will leave prevent the "clean-up" code in the UploadFinished.

Am I doing something wrong or missing something?  Is there another event that always fires?

Thanks.


Sanitized sample code:
Private Sub Upload()
 
        Me.radBusyIndicator.IsBusy = True
 
        Uploader = New RadUpload()
        Uploader.UploadServiceUrl = clsGlobalSettings.sDescriptionUploaderReference
        Uploader.TargetFolder = clsGlobalSettings.sBaseServerReference & "/DesktopModules/WebServices"
        Uploader.OverwriteExistingFiles = True
 
        For Each section As clsChecklistSection In pcolChangedSections
            Dim objBytes As Byte() = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(section.RTFDescription)
            Dim objStream As New System.IO.MemoryStream(objBytes)
            Uploader.CurrentSession.SelectedFiles.Add(New RadUploadSelectedFile(objStream, section.ChecklistSectionName))
        Next
 
        Uploader.PrepareSelectedFilesForUpload()
        Uploader.StartUpload()
         
    End Sub
 
    Private Sub UploadStarted(ByVal sender As System.Object, ByVal e As Telerik.Windows.Controls.UploadStartedEventArgs) Handles Uploader.UploadStarted
 
        System.Diagnostics.Debug.WriteLine("UploadStarted")
 
    End Sub
 
    Private Sub UploadFinished(ByVal sender As System.Object, ByVal e As RoutedEventArgs) Handles Uploader.UploadFinished
 
        System.Diagnostics.Debug.WriteLine("UploadFinished")
 
        Me.radBusyIndicator.IsBusy = False
 
    End Sub
 
    Private Sub FileUploadStarting(ByVal sender As System.Object, ByVal e As FileUploadStartingEventArgs) Handles Uploader.FileUploadStarting
 
        System.Diagnostics.Debug.WriteLine("FileUploadStarting")
 
    End Sub
 
    Private Sub FileUploadFailed(ByVal sender As System.Object, ByVal e As Telerik.Windows.Controls.FileUploadFailedEventArgs) Handles pobjRTFUploader.FileUploadFailed
 
        System.Diagnostics.Debug.WriteLine("FileUploadFailed")
 
        ' Some errors don't cause the UploadFinished event to fire for some reason, leaving us in a "hung" state.
        ' In particular, if the handler is wrong, we don't ever get UploadFinished.
        ' So, to indicate that this has happened, we update the "hung" busy indicator's text.
        radBusyIndicator.BusyContent = e.ErrorMessage
 
    End Sub
".

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 27 Jan 2012, 11:34 AM
Hi John,

The UploadFinished event is only fired if an upload session has finished - even if the upload has failed. However, when the RadUpload control can't find the upload handler, it cannot start an upload sessions and this is why only the FileUploadFailed event is fired.

So in your case you can add some additional logic to stop the BusyIndicator if the RadUplaod control has failed without starting an upload session. You can use the RadUpload.ProgressChanged event to check if a session has started. If a session hasn't started you can change the BusyIndicator.IsBusy value in the FileUploadFailed event:
Private Sub RadUpload1_FileUploadFailed(sender As Object, e As FileUploadFailedEventArgs)
    System.Diagnostics.Debug.WriteLine("FileUploadFailed")
    ' Some errors don't cause the UploadFinished event to fire for some reason, leaving us in a "hung" state.
    ' In particular, if the handler is wrong, we don't ever get UploadFinished.
    ' So, to indicate that this has happened, we update the "hung" busy indicator's text.
    radBusyIndicator.BusyContent = e.ErrorMessage
 
    If Not sessionStarted Then
        Me.radBusyIndicator.IsBusy = False
    End If
End Sub
 
Private sessionStarted As Boolean = False
Private Sub RadUpload1_ProgressChanged(sender As Object, e As RoutedEventArgs)
    sessionStarted = True
End Sub

This way you'll cover all upload failure scenarios. Give this approach a try and let me know if it works for you.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Stephen
Top achievements
Rank 2
answered on 27 Jan 2012, 09:15 PM
Thanks for the suggestion.  That will get the job done.

My need for symmetry screams for an event to tie off the UploadStarted event that *is* raised is this scenario, analogous to FileUploadStarting--FiledUploaded/FileUploadFailed, but I'll manage :-).



Thanks.
Tags
Upload
Asked by
Stephen
Top achievements
Rank 2
Answers by
Tina Stancheva
Telerik team
Stephen
Top achievements
Rank 2
Share this question
or