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

C# MVC File Manager - how to prevent folders from being created within other folders?

3 Answers 393 Views
FileManager
This is a migrated thread and some comments may be shown as answers.
Guilherme
Top achievements
Rank 1
Guilherme asked on 23 Nov 2020, 10:43 AM

Hi,

In short, I don't want Folders to be inside of Folders. Basically I want root > all folders > files inside of folders

I don't want the possibility of creating a folder when the user is already inside of a folder.

Also, how can I make the method Create to NOT create a folder in the UI?

Even if I have this code inside of the Create method:

return Json(new { success = false, errMess = string.Empty }, JsonRequestBehavior.AllowGet);

In the UI it will still display a folder, although null (undefined, and null properties).

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 25 Nov 2020, 09:04 AM

Hello Guilherme,

A possible approach would be to prevent the execute event if the e.command is CreateFolderCommand and if there is a selected folder:

execute:function(e){
  if(e.command === "CreateFolderCommand" && $(".k-in.k-state-selected").length > 0){
    e.preventDefault();
  }
},

Here is a small example for reference.

Let me know how that works for you.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Guilherme
Top achievements
Rank 1
answered on 25 Nov 2020, 09:16 AM

Hello Martin,

 

The problem is I have the File Manager in the .cshtml file using the C# syntax, not javascript, like this:

01.@(Html.Kendo().FileManager()
02.        .Name("FileManager")
03.        .DataSource(ds =>
04.        {
05.            ds.Read(operation => operation.Type(HttpVerbs.Post).Action("Read", "FileManager", new { instructionId = Model.InstructionId }).Data("cldocumentManagement.readFileManager"));
06.            ds.Destroy(operation => operation.Type(HttpVerbs.Post).Action("Destroy", "FileManager"));
07.            ds.Create(operation => operation.Type(HttpVerbs.Post).Action("Create", "FileManager").Data("cldocumentManagement.isDirectorySelected"));
08.            ds.Update(operation => operation.Type(HttpVerbs.Post).Action("Update", "FileManager"));
09.        })
10.        .UploadUrl("Upload", "FileManager", new { instructionId = Model.InstructionId })
11.        .Toolbar(tb => tb.Items(items =>
12.        {
13.            items.Add("createFolder");
14.            items.Add("upload");
15.            items.Add("sortDirection");
16.            items.Add("sortField");
17.            items.Add("changeView");
18.            items.Add("spacer");
19.            items.Add("details");
20.            items.Add("search");
21.        }))
22.        .ContextMenu(context => context.Items(items =>
23.        {
24.            items.Add("rename");
25.            items.Add("delete");
26.        })))
0
Accepted
Martin
Telerik team
answered on 27 Nov 2020, 07:08 AM

Hello Guilherme,

The suggested approach should work just as good in an MVC project after you subscribe to the execute event:

.Events(e=>e.Execute("onExecute"))

<script>
       function onExecute(e) {
            if(e.command === "CreateFolderCommand" && $(".k-in.k-state-selected").length > 0){
                  e.preventDefault();
             }
       }
</script>

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
FileManager
Asked by
Guilherme
Top achievements
Rank 1
Answers by
Martin
Telerik team
Guilherme
Top achievements
Rank 1
Share this question
or