FileManager - capture server command response

1 Answer 13 Views
FileManager
Richard
Top achievements
Rank 4
Bronze
Bronze
Iron
Richard asked on 27 Aug 2025, 02:16 PM

Good afternoon,

I have a FileManager that I want to perform server-side checks when directories or files are renamed or deleted. For instance, the directory has files that must be kept.

I was hoping to use the command event:

command - API Reference - Kendo UI FileManager - Kendo UI for jQuery

Which mentions:

  • Fired when server command is executed (copy, move, delete or rename).
  • The event is useful to get feedback when server commands has failed or succeeded and take additional actions based on the status.

How, in my delete or update server methods, do I force an e.status of fail, and e.response text explaining why the delete or update was rejected, so I can handle that in the client Command event?

I can see that I could throw an error and then capture that in the Error event, but is it possible to do similar with the Command event?  The scenario I'm describing isn't really an error, just some validation that failed.

Kind regards,

Richard

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 01 Sep 2025, 05:31 AM

Hello Richard,

Thank you for the details provided.

You can handle server-side validation failures in the FileManager's Command event by customizing the server response in your delete or update methods. This approach allows you to communicate validation issues (such as protected files in a directory) to the client without triggering the Error event, since these are not actual errors but business rule validations.

How to return a custom response from the server:

  • In your server-side action (for delete, rename, etc.), return a JSON object with a status property (e.g., "fail") and a message describing the validation issue.

Example server-side code (C#):

return Json(new {
    status = "fail",
    message = "Cannot delete directory: contains files that must be kept."
});

Handling the response in the client Command event:

  • In your FileManager initialization, use the command event to check the response status and display the validation message.

Example client-side code:

$("#filemanager").kendoFileManager({
    // ... other configuration ...
    command: function(e) {
        if (e.status === "fail") {
            alert(e.response.message); // Show the validation failure to the user
            // Optionally, prevent further actions or update UI as needed
        }
        // Handle successful operations as usual
    }
});

Summary:

  • This method allows you to treat validation failures separately from actual errors, using the Command event for feedback.
  • You do not need to throw exceptions or use the Error event for validation logic.

For more details, refer to the FileManager Command event documentation:

I hope this information helps.

 

    Kind Regards,
    Anton Mironov
    Progress Telerik

    Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

    Richard
    Top achievements
    Rank 4
    Bronze
    Bronze
    Iron
    commented on 01 Sep 2025, 10:02 AM

    Hi Anton,

    Many thanks for your reply.

    I had already tried something similar, which didn't seem to work.  I've now implemented your suggestion and it still doesn't appear to accept the status and message I'm sending.

    Here's how I've got it set up.

    Client-side code:

       @(Html.Kendo().FileManager().Name("filemanager")
           .DataSource(ds =>
           {
               ds.Read(operation => operation
                   .Type(HttpVerbs.Post)
                   .Action("Read", "FileManager")
                   .Data("getEnvironment")
               );
               ds.Destroy(operation => operation
                   .Type(HttpVerbs.Post)
                   .Action("Destroy", "FileManager")
                   .Data("sendingAdditionalParameter")
               );
               ds.Create(operation => operation
                   .Type(HttpVerbs.Post)
                   .Action("Create", "FileManager")
                   .Data("sendingAdditionalParameter")
               );
               ds.Update(operation => operation
                   .Type(HttpVerbs.Post)
                   .Action("Update", "FileManager")
                   .Data("sendingAdditionalParameter")
               );
           })
           .Toolbar(tb => tb.Items(items =>
           {
               items.Add("createFolder");
               items.Add("sortDirection");
               items.Add("sortField");
               items.Add("changeView");
               items.Add("spacer");
               items.Add("details");
               items.Add("search");
           }))
           .ContextMenu(context => context.Items(items =>
           {
               items.Add("rename");
               items.Add("delete");
           }))
           .Events(events => events
               .Command("onCommand")
               .Error("onError")
           )
       )

    function onCommand(e) { console.log("Command " + e.action + " = item: " + e.data.item.path + "; status: " + e.status); if (e.status === "fail") { e.sender.refresh(); var respsonse = e.response.message; if (response) { $("#error-message").html(response + "<br /><br />"); } } }

    Server-side code (C#):

            [ValidateAntiForgeryToken]
            public virtual async Task<ActionResult> DestroyAsync(FileModel entry, int environmentId)
            {
                if (environmentId > 0)
                {
                    var flag = true;
                    string responseText = string.Empty;
    
                    // Get list of folders mapped in the selected Environment
                    var folders = GetFolders(environmentId);
    
                    var path = NormalizePath(entry.Path);
    
                    if (!string.IsNullOrEmpty(path))
                    {
                        if (entry.IsDirectory)
                        {
                            // Check for mapping in db
                            var folder = folders.Any(l => l.Location == entry.Path);
    
                            if (folder)
                            {
                                flag = false;
                                responseText = "This folder is mapped in the database and cannot be deleted.";
                            }
                            else
                            {
                                DeleteDirectory(path);
                            }
                        }
                        else
                        {
                            DeleteFile(path);
                        }
                    }
    
                    if (!flag)
                    {
                        return Json(new { status = "fail", message = responseText });
                    }
                }
    
                return Json(Array.Empty<object>());
            }

    This is the outcome shown in the console:

    Is there something obvious that I'm missing?

    Kind regards,

    Richard

    Tags
    FileManager
    Asked by
    Richard
    Top achievements
    Rank 4
    Bronze
    Bronze
    Iron
    Answers by
    Anton Mironov
    Telerik team
    Share this question
    or