Display dialog within FileManager

Hi,

I've integrated FileManager component successfully from Syncfusion EJ2 19.4.0.56 into my personal ASP.NET Core MVC 6 application. I've used it in the following view:


Index.cshtml

@using Syncfusion.EJ2
@{
    string[] items = new string[] { "Delete", "Download", "SortBy", "Refresh", "Selection", "Details" };
    string[] files = new string[] { "Delete", "Download", "|", "Details" };
    string[] folder = new string[] { "Delete", "Download", "|", "Details" };
    string[] layout = new string[] { "SortBy", "Refresh", "|", "Details", "|", "SelectAll" };
}
<h1>@T["File manager"]</h1>
@Html.AntiForgeryToken()
<div class="col-lg-12 control-section">
    <div class="control_wrapper">
        <ejs-filemanager id="filemanager-ui"
            beforeSend="beforeSend"
            view="@Syncfusion.EJ2.FileManager.ViewType.Details">
                <e-filemanager-ajaxsettings url="/Admin/FileManager/FileOperations"
                                            downloadUrl="/Admin/FileManager/Download">
                </e-filemanager-ajaxsettings>
                <e-filemanager-contextmenusettings file="files" folder="folder" layout="layout">
                </e-filemanager-contextmenusettings>
                <e-filemanager-toolbarsettings items="items">
                </e-filemanager-toolbarsettings>
                <e-filemanager-navigationpanesettings visible="true">
                </e-filemanager-navigationpanesettings>
        </ejs-filemanager>
    </div>
</div>
<style>
    #filemanager-ui .e-empty-inner-content {
        display: none;
    }
</style>
<script>
    ...
</script>

where  url="/Admin/FileManager/FileOperations" and downloadUrl="/Admin/FileManager/Download" invoke actions of an controller (see the snippet below).

[HttpPost]
public async Task<object> FileOperations([FromBody] FileManagerDirectoryContent args)
{
    try
    {
        ...
        if (args.Action == "delete" || args.Action == "rename")
        {
            if ((args.TargetPath == null) && (args.Path == ""))
            {
                FileManagerResponse response = new FileManagerResponse();
                ErrorDetails er = new ErrorDetails
                {
                    Code = "401",
                    Message = "Restricted to modify the root folder."
                };
                response.Error = er;
                return _operation.ToCamelCase(response);
            }
        }
        ...
    }
    catch (Exception e)
    {
        _logger.LogError(e.ToString());
        throw;
    }
}
[HttpPost]
public async Task<IActionResult> Download(string downloadInput)
{
    try
    {
        ...
FileManagerDirectoryContent args = JsonConvert.DeserializeObject<FileManagerDirectoryContent>(downloadInput);
        ...
return _operation.Download(args.Path, args.Names);
    }
    catch (Exception e)
    {
        _logger.LogError(e.ToString());
        throw;
    }
}

How can I display a dialog with file manager? I need it to show any errors from the action above.


5 Replies

IL Indhumathy Loganathan Syncfusion Team March 22, 2022 11:57 AM UTC

Hi Domenico, 
 
Greetings from Syncfusion support. 
 
By default, the File Manager component throws an error message in the dialogue popup whenever a file operation fails. We have provided in-build support for error handling, so the error dialogue will be a popup for file operation failures in the File Manager component. This is the default behavior of the File Manager.  
 
Kindly check this at your end. Whether you want to add custom error messages to the dialog Please explain your use case with the File Manager component to provide a prompt solution. 
 
Regards, 
Indhumathy L 



DC Domenico Carlo March 24, 2022 09:40 AM UTC

I need to display the message "Restricted to modify the root folder." and the exception to the dialog.



IL Indhumathy Loganathan Syncfusion Team March 28, 2022 01:53 PM UTC

Hi Domenico,  
 
By default, File Manager doesn't support root folder deletion. We have completely prevented the delete operation for the root folder. Please check the below sample for reference. 
 
 
Could you please share with us the detailed explanation of your exact use case? Are you removing the root folder at the server end? These details would help us assist you promptly. Please let us know if you need any further assistance. 
 
Regards, 
Indhumathy L 



DC Domenico Carlo replied to Indhumathy Loganathan March 29, 2022 04:46 AM UTC

I need to show any custom dialog message when the methods  FileOperations() and Download() are invoked.



IL Indhumathy Loganathan Syncfusion Team March 30, 2022 12:43 PM UTC

Hi Domenico,


In File Manager, you can use the failure event to retrieve the error code and message for all file operation failures. You can customize the default code and error messages here. Check the below code snippet.


function failure(args) {

  if (args.error.code == '404') {

    //Modify the error message

    args.error.message = 'Failed to send request to an invalid Url';

  }

  console.log(args);

  //Append the modified error message in dialog

  document.querySelector('.e-fe-errorcontent').innerText = args.error.message;

}


We have already handled a similar requirement in the below forum.


http://www.syncfusion.com/forums/165840/provision-for-custom-messages?reply=SEgTKT


Kindly check whether the provided details meet your requirement and get back to us if you need any further assistance.


Regards,

Indhumathy L


Loader.
Up arrow icon