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

How To Test Whether Upload/Download Was Successful

4 Answers 113 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 01 Oct 2012, 05:15 PM

Hi,

 

I am using the FileExplorer and I have EnableAsyncUpload set to true. I have also applied these modifications so that the Open menu option will always force a download.

 

With the Telerik AsynchUpload control, I can use the OnClientValidationFailed to verify the status of an upload. I need to be able to do this when clicking the Upload toolbar button within FileExplorer. But I don’t want to validate a “failed” upload; I want to validate a “successful” upload.

 

And I’m not sure that either test can be preformed when forcing a download, since I am actually invoking my browser’s “Save As” feature, as opposed to a Telerik download feature.

 

Any suggestions?
Thanks,
Steven

4 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 04 Oct 2012, 12:51 PM
Hi,

I am not quite sure if I understand the issue correctly.
  • If you simply want to verify if a file has been uploaded successfully, you could get a reference to the FileExplorer's AsyncUpload control and to handle its OnClientUploaded event, calling of which will validate a successful upload.
  • If you want to control the uploading process in some way, you could make the verification in the FileExplorer's AsyncUpload's OnClientUploading event and to set its args.set_cancel("true") if the predefined requirements are not satisfied.

You could attach the handlers to the above mentioned AsyncUpload events in the following way:
<telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" OnClientLoad="OnClientLoad">
    <Configuration ViewPaths="~/" DeletePaths="~/" UploadPaths="~/" EnableAsyncUpload="true"/>
</telerik:RadFileExplorer>
<script type="text/javascript">
    function OnClientLoad(sender, args) {
        var asyncUpload = sender.get_asyncUpload();
        if(asyncUpload)
        {
            asyncUpload.add_fileUploading(OnClientFileUploading);
            asyncUpload.add_fileUploaded(OnClientFileUploaded);
        }
    }
    function OnClientFileUploading(sender, args) {
        alert(1);
    }
    function OnClientFileUploaded(sender, args) {
        alert(2);
    }
</script>


Additionally, all of these approaches are applicable to the FileExplorer's events, and they could not control the standard browser behavior. But since you are invoking only browser's "Save as", and you are using the FileExplorer's upload functionality that is not supposed to be of any obstacle when testing whether the file has or has not been uploaded.

Regards,
Vesi
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Brian
Top achievements
Rank 1
answered on 04 Oct 2012, 03:13 PM
Hi Vesi,
Thank you for replying to my post. I apologize for not being clear with my description of the problem.

I am familiar with the client-side events associated with the RadAsyncUpload, but the ClientFileUploading and ClientFileUploaded do not necessarily meet my objective. These 2 events fire during or after clicking [Select].

Specifically, when I browse to my page that has the RadFileExplorer, and click Upload (on the toolbar of FileExplorer), a popup window appears, which I believe is a RadWindow (at least, I think that’s what it is, right?) The window that appears has a [Select] button and an [Upload] button. Clicking [Select] will fire the ClientFileUploading and ClientFileUploaded events respectively (clicking [Select], choosing a file, and then clicking [Open]).

Instead of events that take place around the [Select] button, what I am trying to do is to use events that surround the [Upload] button. So when a user clicks [Upload], I want the click event to continue doing what it is designed to do, but in addition, I also want to be able to call my own JavaScript function (or code-behind, whichever is possible).

Maybe I could use the OnClientClose event, but I don’t want my JavaScript to run simply because the user closed the RadWindow. For example, if the user clicks X in the upper-right of the RadWindow, I do not want my JavaScript to run. I only want the script to run when [Upload] is clicked. So how do I capture and utilize the click (or other events)  of the [Upload] button? Are there other client-side events that I am overlooking?

Please let me know if I can provide you with any other information.

Thank you for your time,
Steven
0
Vessy
Telerik team
answered on 05 Oct 2012, 10:52 AM
Hi Steven,

The "Upload" button that is inside the "Upload dialog" is a standard RadButton and you could access both its Clicked or Clicking client events as follows:
<script type="text/javascript">
    function OnClientLoad(sender, args) {
        var asyncUpload = sender.get_asyncUpload();
        var uploadButton = $find("<%= RadFileExplorer1.ClientID%> + "_btnUpload");//get reference to the Upload button
         
        if(asyncUpload)
        {
            uploadButton.add_clicking(function(){alert(1);});//assign clicking handler
            uploadButton.add_clicked(function(){alert(2);});//assign clicked handler
        }
    }
</script>

Additionally, if these events do not fit your scenario, could you, please, describe in more details what functionality exactly do you want to achieve? There are some specific scenarios which cannot be easily achieved (e.g. triggering additional AJAX requests) and only if we know what the expected result is will be able to provide more-to-the-point answer.

Kind regards,
Vesi
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Brian
Top achievements
Rank 1
answered on 12 Nov 2012, 05:36 PM
BTW Vesi, your suggestions worked, so thank you.
Steven
Tags
FileExplorer
Asked by
Brian
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Brian
Top achievements
Rank 1
Share this question
or