FileExplorer, Document Manager, and Image Manager display an error message when a file upload fails

1 Answer 5 Views
Editor FileExplorer
lan luo
Top achievements
Rank 1
Iron
lan luo asked on 27 May 2025, 07:03 PM

Hello,

One of our customers reported that they are trying to enhance the security features for file uploads in RadFileExplorer, Document Manager, and Image Manager. Specifically, for SVG files, they want to inspect the file contents for any embedded JavaScript functions. If the file is deemed unsafe, the upload should fail, and an error message should be displayed to the end user.

We have implemented the necessary backend validation and are able to throw an error message. However, we have not found a way to display this error message in the UI. Is there a recommended approach for implementing error message display in this scenario?

Thanks,

Lan

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 28 May 2025, 11:03 AM

Hi Lan,

You can attach the OnClientFileUploadFailed error handler to the AsyncUpload used in the Image Manager and provide the error message which will be thrown when uploading the file. You can access the AsyncUpload control in the FileBrowser dialogs of RadEditor using as a base the code solution provided in this KB article: Displaying single upload control in the FileBrowser Upload manager.

Here is an example how to attach the OnClientFileUploadFailed error handler to the AsyncUpload:

UserControl.ascx

C#

<script runat="server" type="text/C#">
    protected void Page_Load(object sender, EventArgs args)
    {
        Telerik.Web.UI.RadFileExplorer rfe = FindRadControl(this.Page) as Telerik.Web.UI.RadFileExplorer;

        if (rfe != null)
        {
            rfe.AsyncUpload.OnClientFileUploadFailed = "OnClientFileUploadFailed";
        }
    }

    private Control FindRadControl(Control parent)
    {
        foreach (Control c in parent.Controls)
        {
            if (c is Telerik.Web.UI.RadFileExplorer) return c;

            if (c.Controls.Count > 0)
            {
                Control sub = FindRadControl(c);
                if (sub != null) return sub;
            }
        }

        return null;
    }
</script>

<script>
function OnClientFileUploadFailed(sender, args) {
  alert(args.get_message()); // this line will alert the error that you get when trying to upload a file
}
</script>

VB

<script runat="server" type="text/VB">
    Protected Sub Page_Load(ByVal sender As Object, ByVal args As System.EventArgs)
        Dim rfe As Telerik.Web.UI.RadFileExplorer = CType(Me.FindRadControl(Me.Page), Telerik.Web.UI.RadFileExplorer)
 
        If rfe IsNot Nothing Then
            rfe.AsyncUpload.OnClientFileUploadFailed= "OnClientFileUploadFailed"
        End If
    End Sub
 
    Private Function FindRadControl(ByVal parent As Control) As Control
        For Each c As Control In parent.Controls
            If TypeOf c Is Telerik.Web.UI.RadFileExplorer Then Return c
 
            If c.Controls.Count > 0 Then
                Dim [sub] As Control = FindRadControl(c)
                If [sub] IsNot Nothing Then Return [sub]
            End If
        Next
 
        Return Nothing
    End Function
</script>
<script>
function OnClientFileUploadFailed(sender, args) {
  alert(args.get_message()); //this line will alert the error that you get when trying to upload a file
}
</script>



    Regards,
    Rumen
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Tags
    Editor FileExplorer
    Asked by
    lan luo
    Top achievements
    Rank 1
    Iron
    Answers by
    Rumen
    Telerik team
    Share this question
    or