All files and folder shown as undefined

1 Answer 262 Views
FileManager
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Rob asked on 07 Dec 2021, 01:36 AM

I copied the demonstration code and controller ( from GitHub) and slightly modified to suit.

The view is very simple

<body>
    <div id="example">
        <div id="filemanager"></div>

        <script>
        $("#filemanager").kendoFileManager({
            dataSource: {
                schema: kendo.data.schemas.filemanager,
                transport: {
                    read: {
                        url: '@Url.Action("Read", "FileManager")',
                        method: "POST"
                    }
                }
            },
            toolbar: {
                items: [
                    { name: "createFolder" },
                    { name: "upload" },
                    { name: "sortDirection" },
                    { name: "sortField" },
                    { name: "changeView" },
                    { name: "spacer" },
                    { name: "details" },
                    { name: "search" }
                ]
            },
            contextMenu: {
                items: [
                    { name: "rename" },
                    { name: "delete" }
                ]
            },
            draggable: true,
            resizable: true
        });

        $(document).ready(function () {
            var filemanager = $("#filemanager").getKendoFileManager();

            filemanager.executeCommand({ command: "TogglePaneCommand", options: { type: "preview" } });
            filemanager.toolbar.fileManagerDetailsToggle.switchInstance.toggle();
        })
        </script>
    </div>




</body>
</html>


The Data returned from the controller is this ( copy and paste from the browser)

[{"name":"English","size":0,"path":"English","extension":"","isDirectory":true,"hasDirectories":false,"created":"\/Date(1638409250788)\/","createdUtc":"\/Date(1638409250788)\/","modified":"\/Date(1638834574019)\/","modifiedUtc":"\/Date(1638834574019)\/"},{"name":"Swedish","size":0,"path":"Swedish","extension":"","isDirectory":true,"hasDirectories":false,"created":"\/Date(1638409251098)\/","createdUtc":"\/Date(1638409251098)\/","modified":"\/Date(1638501536659)\/","modifiedUtc":"\/Date(1638501536659)\/"}]

I have tried viewing a folder with lots of file.. the number of File is always right.. but something is going wrong with the reading of the data being returned The initial controller code I used set path as a path and filename. I changed it to above to match what I can see returning for the examples provided.
So  now I believe the JSON being returned from the online samples that are using the same backend are identical to what I am returning. 

I am using 2021.1.330.     The only thing I can think of is that there was a change in the Schema between versions? But I cannot find anything about this

I haven't got much hair left these days... would really appreciate a pointer to at least what I could be checking.

Many thanks

Rob

1 Answer, 1 is accepted

Sort by
0
Accepted
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 07 Dec 2021, 03:36 AM

OK, I found it

There seems to have been a change to the case of the fields between versions

If I look at the demo's online and watch the read JSON response, everything is camelCase.

But then I dug into my version, I can see the field is capitalised ( see new file uploaded)

So I changed the code from the GitHub data source that is provided, to return the fields with a capital, and it works now

I used the controller from kendo-ui-demos-service

 public virtual JsonResult Read(string target)
        {
            var path = NormalizePath(target);

            if (AuthorizeRead(path))
            {
                try
                {
                    directoryProvider.Server = Server;

                    var result = directoryProvider
                        .GetContent(path, DefaultFilter)
                        .Select(f => new
                        {
                            name = f.Name,
                            size = f.Size,
                            path = ToVirtual(f.Path),
                            extension = f.Extension,
                            isDirectory = f.IsDirectory,
                            hasDirectories = f.HasDirectories,
                            created = f.Created,
                            createdUtc = f.CreatedUtc,
                            modified = f.Modified,
                            modifiedUtc = f.ModifiedUtc
                        });

                    return Json(result, JsonRequestBehavior.AllowGet);
                }
                catch (DirectoryNotFoundException)
                {
                    throw new HttpException(404, "File Not Found");
                }
            }

            throw new HttpException(403, "Forbidden");
        }
But had to adjust this to return capitalised fields 

I assume this is a version issue. I did check the history in GitHub earlier, but didn't see any changes. Maybe I missed it

Sorry to take your time and hopefully this helps someone else
Mark
Top achievements
Rank 1
commented on 26 Jun 2023, 10:41 PM

Clear as mud... :)  Could you upload your example controller and the respectively altered class(es)?

-Mark

Rob
Top achievements
Rank 2
Iron
Veteran
Iron
commented on 27 Jun 2023, 12:31 AM

Hey Mark

Sorry, it's not very clear is it!

My code is very different now and probably not useful , but I will try to explain clearer!

The key issue is that the controller was returning json fields with lower case names. (name, size, path etc)

[{"name":"English","size":0,"path":"English","extension":"" ......

But the client was not recognising this, it expected the json return to be like this.. (Name, Size, Path etc)

[{"Name":"English","Size":0,"path":"English","Extension":"" .......

To solve this, I changed all the definitions of the objects being returned to have capitalized property names 

for example

Public Class FileManagerEntry
        Public Property Name As String
        Public Property Size As Long
        Public Property Path As String
        Public Property Extension As String
        Public Property IsDirectory As Boolean
        Public Property HasDirectories As Boolean
        Public Property Created As DateTime
        Public Property CreatedUtc As DateTime
        Public Property Modified As DateTime
        Public Property ModifiedUtc As DateTime
        Public Property Directories As IEnumerable(Of FileManagerEntry)
    End Class

There is probably a much smarter way to resolve this, but I was just happy to get it working!

Hope that is a little clearer.

Regards

Rob

Tags
FileManager
Asked by
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or