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.
I need to display the message "Restricted to modify the root folder." and the exception to the dialog.
I need to show any custom dialog message when the methods FileOperations() and Download() are invoked.
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