Disable delete key for certain folder or file

Hi

How can I disable the delete key for certain folders and files in the FileManager. The Delete Folder dialog should also not be shown.

Regargs, Bruno


1 Reply

PS Praveen Sellappan Syncfusion Team February 24, 2026 06:15 PM UTC

Hi Bruno,


Greetings from Syncfusion Support.


Yes, this can be achieved using the BeforePopupOpen event of the FileManager component.


In the sample we’ve prepared for you:


  • In the BeforePopupOpen event handler, we retrieve the currently selected files/folders using the getSelectedFiles() method.
  • We then check the names of the selected items against the ones you want to protect from deletion (in this demo, we prevent deletion of the "Music" folder you can easily customize this logic to match your specific file/folder names or conditions).
  • If the popup type is "delete" and one of the protected items is selected, we set args.cancel = true to block the delete action and prevent the confirmation popup from proceeding.


This approach gives you full control to block deletion for any specific files or folders based on your rules.


Here’s the sample for your reference: https://blazorplayground.syncfusion.com/hDBnZVVJnfaVxCVL


Code Snippet:


<SfFileManager TValue="FileManagerDirectoryContent" @ref="fileManager">

    <FileManagerEvents TValue="FileManagerDirectoryContent" BeforePopupOpen="open"></FileManagerEvents>

</SfFileManager>

@code {

    SfFileManager<FileManagerDirectoryContent> fileManager;

    private void open(BeforePopupOpenCloseEventArgs args)

    {

        var selecteditems = fileManager.GetSelectedFiles();

        if (selecteditems[0].Name == "Music" && args.PopupName=="Delete")

        {

            args.Cancel = true;

        }

    }

   

}

 


Please review the sample, test it with your scenario, and let us know if it fully addresses your requirement.


Regards,

Praveen Sellappan


Loader.
Up arrow icon