How to display only .jpg or .pdf files in File Manager

How to display only .jpg or .pdf files in File Manager


1 Reply

IL Indhumathy Loganathan Syncfusion Team July 13, 2022 02:43 PM UTC

Hi Kaustubh,


Greetings from Syncfusion support.


We have validated your requirement in FileManager component. The FileManager displays the files and folders that are returned from the server. You can perform required customization in FileManager read operation and return the required files/folders to client side. We have prepared a simple sample which will prevent the jpg files from displaying in FileManager. We have returned the files that are not with .jpg and .pdf extension in read operation. Please check the below code snippet.


case "read":

    // reads the file(s) or folder(s) from the given path.

    FileManagerResponse readResult = this.operation.GetFiles(args.Path, args.ShowHiddenItems);

    if ((readResult.Error == null))

    {

        List<FileManagerDirectoryContent> newFiles = new List<FileManagerDirectoryContent>();

        foreach (FileManagerDirectoryContent file in readResult.Files)

        {

            FileInfo fi = new FileInfo(file.Name);

            //Allow .jpg, .pdf and folders.

            if (fi.Extension == ".jpg" || fi.Extension == ".pdf" || fi.Extension == "")

            {

                // Return the file from Controller.

                newFiles.Add(file);

            }

        }

        readResult.Files = newFiles;

    }

    return this.operation.ToCamelCase(readResult);


Sample: https://stackblitz.com/edit/angular-m4ccvy?file=app.component.ts


Service provider: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-aspcore-file-provider440423764


Please check the shared sample and get back to us if you need any further assistance.


Regards,

Indhumathy L


Loader.
Up arrow icon