Unplanned
Last Updated: 05 Nov 2025 09:20 by Victoria
Victoria
Created on: 05 Nov 2025 09:20
Category: FileManager
Type: Bug Report
1
FileManager does not automatically expand the selected TreeView item or to the currently open folder

The FileManager TreeView does not expand automatically in some scenarios, which can cause the TreeView and ListView UI to be inconsistent:

  • Programmatic Path change.
  • When clicking on a folder in the TreeView.
  • When navigating to a folder from the ListView, while its parent is not already expanded.

Here is a test page and steps to reproduce.

Test 1

  1. Copy `/folder-16/folder-17` in the textbox and hit Enter.
  2. The FileManager navigates to the specified folder and the TreeView selects it, but does not expand.

Test 2

  1. Click on `folder-16` in the TreeView.
  2. The TreeView does not expand, but it should.
  3. Double-click `folder-17` in the ListView.
  4. The FileManager navigates and the TreeView selects the new folder, but does not expand.

<p>/folder-16/folder-17</p>

<TelerikTextBox @bind-Value="@DirectoryPath" Width="max-content" OnChange="@(() => FileManagerRef!.Rebind())" />

<TelerikFileManager @ref="@FileManagerRef"
                    Data="@FileManagerData"
                    @bind-Path="@DirectoryPath"
                    View="@FileManagerViewType.ListView"
                    EnableLoaderContainer="false"
                    OnDownload="@OnDownloadHandler"
                    NameField="@(nameof(FlatFileEntry.Name))"
                    SizeField="@(nameof(FlatFileEntry.Size))"
                    PathField="@(nameof(FlatFileEntry.Path))"
                    ExtensionField="@(nameof(FlatFileEntry.Extension))"
                    IsDirectoryField="@(nameof(FlatFileEntry.IsDirectory))"
                    HasDirectoriesField="@(nameof(FlatFileEntry.HasDirectories))"
                    IdField="@(nameof(FlatFileEntry.Id))"
                    ParentIdField="@(nameof(FlatFileEntry.ParentId))"
                    DateCreatedField="@(nameof(FlatFileEntry.DateCreated))"
                    DateCreatedUtcField="@(nameof(FlatFileEntry.DateCreatedUtc))"
                    DateModifiedField="@(nameof(FlatFileEntry.DateModified))"
                    DateModifiedUtcField="@(nameof(FlatFileEntry.DateModifiedUtc))"
                    Class="my-filemanager">
</TelerikFileManager>

@code {
    private TelerikFileManager<FlatFileEntry>? FileManagerRef { get; set; }

    private List<FlatFileEntry>? FileManagerData { get; set; }

    public string? DirectoryPath { get; set; } = string.Empty;

    private readonly string RootPath = string.Empty;

    public async Task<bool> OnDownloadHandler(FileManagerDownloadEventArgs args)
    {
        await Task.Delay(1);

        return true;
    }

    private int FolderLevelCount { get; set; } = 5;
    private int FilesInFolderCount { get; set; } = 5;
    private int FoldersInFolderCount { get; set; } = 2;
    private int FolderNameCounter { get; set; }
    private readonly List<string> FileExtensions = new() {
            ".txt", ".pdf", ".docx", ".xlsx", ".png", ".jpg", ".gif", ".zip", ".css", ".html", ".mp3", ".mpg"
        };

    protected override async Task OnInitializedAsync()
    {
        await Task.CompletedTask;

        DirectoryPath = RootPath;

        FileManagerData = LoadFlatDataAsync();

        await base.OnInitializedAsync();
    }

    private List<FlatFileEntry> LoadFlatDataAsync()
    {
        List<FlatFileEntry> data = new List<FlatFileEntry>();

        string rootDataPath = string.IsNullOrEmpty(RootPath) ? "/" : RootPath;

        PopulateChildren(data, null, rootDataPath, 1);

        return data;
    }

    private void PopulateChildren(List<FlatFileEntry> data, string? parentId, string parentPath, int level)
    {
        var rnd = Random.Shared;

        for (int i = 1; i <= FilesInFolderCount; i++)
        {
            string itemId = Guid.NewGuid().ToString();
            string itemExtension = FileExtensions[rnd.Next(0, FileExtensions.Count)];
            string itemName = $"{itemExtension.Substring(1)}-file-{(FolderNameCounter != default ? string.Concat(FolderNameCounter, "-") : string.Empty)}{i}";
            string itemPath = Path.Combine(parentPath, string.Concat(itemName, itemExtension));

            data.Add(new FlatFileEntry()
            {
                Id = itemId,
                ParentId = parentId,
                Name = itemName,
                IsDirectory = false,
                HasDirectories = false,
                DateCreated = DateTime.Now,
                DateCreatedUtc = DateTime.Now.ToUniversalTime(),
                DateModified = DateTime.Now,
                DateModifiedUtc = DateTime.Now.ToUniversalTime(),
                Path = itemPath,
                Extension = itemExtension,
                Size = rnd.Next(1_000, 3_000_000)
            });
        }

        if (level < FolderLevelCount)
        {
            for (int i = 1; i <= FoldersInFolderCount; i++)
            {
                var itemId = Guid.NewGuid().ToString();
                var itemName = $"folder-{++FolderNameCounter}";
                var itemPath = Path.Combine(parentPath, itemName);

                data.Add(new FlatFileEntry()
                {
                    Id = itemId,
                    ParentId = parentId,
                    Name = itemName,
                    IsDirectory = true,
                    HasDirectories = level < FolderLevelCount - 1,
                    DateCreated = DateTime.Now,
                    DateCreatedUtc = DateTime.Now.ToUniversalTime(),
                    DateModified = DateTime.Now,
                    DateModifiedUtc = DateTime.Now.ToUniversalTime(),
                    Path = itemPath,
                    Size = rnd.Next(100_000, 10_000_000)
                });

                PopulateChildren(data, itemId, itemPath, level + 1);
            }
        }
    }

    public class FlatFileEntry : FileEntry
    {
        public string Id { get; set; } = Guid.NewGuid().ToString();

        public string ParentId { get; set; }
    }

    public class FileEntry
    {
        public string Name { get; set; }

        public long Size { get; set; }

        public string Path { get; set; }

        public string Extension { get; set; }

        public bool IsDirectory { get; set; }

        public bool HasDirectories { get; set; }

        public DateTime DateCreated { get; set; }

        public DateTime DateCreatedUtc { get; set; }

        public DateTime DateModified { get; set; }

        public DateTime DateModifiedUtc { get; set; }
    }
}

0 comments