Changing the root folder in File Manager

Hello,


Is there a way to assign the root folder by passing in a value when opening the file manager so that you can only view that specific folder? 


EX. 

right now it is, root -> folder1 -> subfolder -> subfolder2, and it shows all the folders from the "root" folder


What I need is, setting "subfolder" as root so that file manger opens up with "subfolder".


Please advise,


7 Replies

PM Prasanth Madhaiyan Syncfusion Team August 4, 2022 12:46 PM UTC

Hi William,


Greetings from Syncfusion support.


We understand that you want to set the required sub folder as the root folder for the File Manager component. For your reference, we have prepared a sample where we sent the folder from the client end to set it as a root folder. You can send the root folder name in the below events from client to server.


File Operations

Events

Read, Delete, Upload, Rename, Copy

beforeSend

GetImage

beforeImageLoad

Download

beforeDownload


Please refer the below code snippet.


[index.cshtml]

 

<ejs-filemanager id="filemanager"  beforeSend="beforeSend" beforeImageLoad="beforeImageLoad" beforeDownload="beforeDownload">

    <e-filemanager-ajaxsettings url="/Home/FileOperations"

                                downloadUrl="/Home/Download"

                                uploadUrl="/Home/Upload"

                                getImageUrl="/Home/GetImage">

    </e-filemanager-ajaxsettings>

</ejs-filemanager>

 

<script>

   

    function beforeSend(args) {

        //Ajax beforeSend event

        args.ajaxSettings.beforeSend = function (args) {

            //Setting authorization header             

                args.httpRequest.setRequestHeader("Authorization", "Pictures");

        }

    }

    function beforeImageLoad(args) {

        var rootFileName = "Pictures";

        args.imageUrl = args.imageUrl + '&rootName=' + rootFileName;

    }

    function beforeDownload(args) {

        var rootFileName = "Pictures" ;

        var includeCustomAttribute = args.data;

        includeCustomAttribute.rootName = rootFileName;

       args.data = includeCustomAttribute;

    }

 

</script>

 

[HomeController.cs]

 

public class HomeController : Controller

{

  public class FileManagerDirectoryContentExtend : FileManagerDirectoryContent

  {

      public string rootName { get; set; }

  }

 

  public object FileOperations([FromBody] FileManagerDirectoryContent args)

  {

      var root = HttpContext.Request.Headers["Authorization"];

      this.operation.RootFolder(this.basePath + "\\" + this.root + "\\" + root);

      …

  }

 

  // Uploads the file(s) into a specified path

 public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action)

  {

      var root = HttpContext.Request.Headers["Authorization"];

      this.operation.RootFolder(this.basePath + "\\" + this.root + "\\" + root);

      …

  }

 

  // Downloads the selected file(s) and folder(s)

  public IActionResult Download(string downloadInput)

  {

        FileManagerDirectoryContentExtend args = JsonConvert.DeserializeObject<FileManagerDirectoryContentExtend>(downloadInput);

        var root = args.rootName;

        if (root != "")

        {

            this.operation.RootFolder(this.basePath + "\\" + this.root + "\\" + root);

        }

        return this.operation.Download(args.Path, args.Names);

  }

 

  // Gets the image(s) from the given path

  public IActionResult GetImage(FileManagerDirectoryContentExtend args)

  {

      var root = args.rootName;

      this.operation.RootFolder(this.basePath + "\\" + this.root + "\\" + root);

      return this.operation.GetImage(args.Path, args.Id, true, null, args.Data);

  }

}


For your reference we have attached the sample.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/CoreFileManagerSample708177038.zip


Please check the shared sample and let us know if you need any further assistance.


Regards,

Prasanth Madhaiyan.



WL william lee August 8, 2022 04:38 PM UTC

Hi Prasanth,


I should've mentioned this before but I am using Amazon S3 for this file manager. Could you kindly provide the example code for S3?


Thank you



PM Prasanth Madhaiyan Syncfusion Team August 9, 2022 09:46 AM UTC

Hi William,


We understand that you want to set the required sub folder as the root folder for the File Manager component. For your reference, we have prepared a sample where we sent the folder from the client end to set it as a root folder. You can send the root folder name in the below events from client to server by setting the folder in the GetBucketList method.


File Operations

Events

Read, Delete, Upload, Rename, Copy

beforeSend

GetImage

beforeImageLoad

Download

beforeDownload


Please refer to the below code snippet.


[index.cshtml]

 

<ejs-filemanager id="filemanager" view="@Syncfusion.EJ2.FileManager.ViewType.Details" beforeSend="beforeSend" beforeImageLoad="beforeImageLoad" beforeDownload="beforeDownload">

    <e-filemanager-ajaxsettings url="/Home/AmazonS3FileOperations"

                            downloadUrl="/Home/AmazonS3Download"

                            uploadUrl="/Home/AmazonS3Upload"

                            getImageUrl="/Home/AmazonS3GetImage">

    </e-filemanager-ajaxsettings>

</ejs-filemanager>

 

<script>

   

function beforeSend(args) {

    //Ajax beforeSend event

    args.ajaxSettings.beforeSend = function (args) {

        //Setting authorization header             

            args.httpRequest.setRequestHeader("Authorization", "Pictures");

    }

}

function beforeImageLoad(args) {

    var rootFileName = "Pictures";

    args.imageUrl = args.imageUrl + '&rootName=' + rootFileName;

}

function beforeDownload(args) {

    var rootFileName = "Pictures" ;

    var includeCustomAttribute = args.data;

    includeCustomAttribute.rootName = rootFileName;

    args.data = includeCustomAttribute;

}

 

</script>

[HomeController.cs]

 

public class HomeController : Controller

{

    public class FileManagerDirectoryContent1 : FileManagerDirectoryContent

    {

        public string RootName { get; set; }

    }

 

    public object AmazonS3FileOperations([FromBody] FileManagerDirectoryContent1 args)

    {

        this.operation.setRootName(args.RootName);

        …

        }

    // uploads the file(s) into a specified path

    public IActionResult AmazonS3Upload(string path, IList<IFormFile> uploadFiles, string action, string data, string rootName)

    {

        this.operation.setRootName(rootName);

                …

        }

    // downloads the selected file(s) and folder(s)

    public IActionResult AmazonS3Download(string downloadInput)

    {

       FileManagerDirectoryContent1 args = JsonConvert.DeserializeObject<FileManagerDirectoryContent1>(downloadInput);

        this.operation.setRootName(args.RootName);

        return operation.Download(args.Path, args.Names);

    }

    // gets the image(s) from the given path

    public IActionResult AmazonS3GetImage(FileManagerDirectoryContent1 args)

    {

        this.operation.setRootName(args.RootName);

        return operation.GetImage(args.Path, args.Id, false, null, args.Data);

    }

}

 

[AmazonS3FileProvider.cs]

 

public class AmazonS3FileProvider : IAmazonS3FileProviderBase

{

    …

    public string FolderName="";

    …

 

    // customization to update the class variable with root folder name received from client side

    public void setRootName(string args)

    {

        FolderName = args;

    }

    //Define the root directory to the file manager

    public void GetBucketList()

    {

        ListingObjectsAsync("", "", false).Wait();

        // setting the root name with custom name attribute and reading the files/folders inside based on that root name

        if (FolderName != null && FolderName != "" && response.S3Objects.Where(x => x.Key.Contains(FolderName)).Select(x => x).ToArray().Length > 0

            && (response.S3Objects.Where(x => x.Key.Contains(FolderName)).Select(x => x).ToArray()).Where(y => y.Key.Split("/").Length == 2 && y.Key.Split("/")[1] == "").Select(y => y).ToArray().Length == 1)

        {

            //  It display the particular folder as root folder.  

            RootName = (response.S3Objects.Where(x => x.Key.Contains(FolderName)).Select(x => x).ToArray()).Where(y => y.Key.Split("/").Length == 2 && y.Key.Split("/")[1] == "").Select(y => y).ToArray()[0].Key;

        }

        else

        {

            // Or else it display the first folder as root folder 

            RootName = response.S3Objects.First().Key;

        }

    }

}


For your reference we have attached the sample.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/CoreFileManagerAmazonProviderRootFolder-1400540315.zip


Please check the shared sample and let us know if you need any further assistance.


Regards,

Prasanth Madhaiyan.



WL william lee August 10, 2022 12:09 AM UTC

Hi Prasanth,


How do I manually set the root folder when opening the file manager. The client should NOT be able to navigate through the folders but only be able to see the contents of one folder. I tried hard coding in the root folder name in the example provided but it keeps showing the entire bucket.




For example, if I only want the folder "2342342" displayed in file manager, how would I do that? 



PM Prasanth Madhaiyan Syncfusion Team August 10, 2022 07:13 AM UTC

Hi William,


As mentioned earlier, the Amazon file service provider only sets the first available folder in the bucket as the root folder, not its sub folders. However, this scenario is considered as a feature from our end, but we do not have any immediate plans to implement this feature. At the planning stage for every release cycle, we review all open features. Usually, Syncfusion will plan and implement the features based on feature rank, customer requested count, and volume wish-list. We will let you know when this feature is implemented


The status of feature implementation can be tracked through the below portal link:


https://www.syncfusion.com/feedback/31885/provide-support-to-set-nested-folder-path-in-amazon-bucket-as-the-root-folder-for


We appreciate your patience.


Regards,

Prasanth Madhaiyan.



WL william lee August 10, 2022 09:25 PM UTC

Hi Prasanth,


Thank you for providing detailed responses to my problem but I found this post where it seems to have the solution to the same question I have. 


I just need it so that they are only able to see the contents of the chosen subfolder without having to navigate through the file manager. 


Really appreciate your assistance,

William



PM Prasanth Madhaiyan Syncfusion Team August 11, 2022 08:44 AM UTC

Hi William,


In the shared forum, we have set the subfolders folder as the root folder of the FileManager with Azure File System Provider. But your earlier query in the Amazon S3 Provider has been considered as a feature at our end, and we have attached the feature feedback in our previous update.


Do you want to set the subfolder folders as the root in the FileManager component by using the Azure File System Provider? Please confirm the provider details and your exact use case if you require any further assistance.


Regards,

Prasanth Madhaiyan.


Loader.
Up arrow icon