Set root directory path

Hello,

I'm trying to use the file manager component by setting dynamically the root directory. The root directory is based on my view model.
I'm using the FileManagerDirectoryContent provider to perform file system operations.

This topic helped me to move the root directory dynamically using the beforeSend event and setting the value of the root folder :

function beforeSend(args) {
    var data = JSON.parse(args.ajaxSettings.data);
    data["RootPath"] = '/Maintenance/Equipments/@Model.Name';
    args.ajaxSettings.data = JSON.stringify(data);
}

But now, when I'm downloading or uploading files, the root folder is not set in the PhysicalFileProvider, and I'm always facing an error.
I tried the workarround given by setting the RootFolder in the HttpContext.Session, but I can't use the session approach because a part of my application is not working anymore this way.

As far as I can see on the community forum, I not the only one trying to set the root directory path.
Can you please provide a way to achieve this easily ?

Best regards,

Julien.

3 Replies 1 reply marked as answer

IL Indhumathy Loganathan Syncfusion Team February 10, 2021 04:02 PM UTC

Hi Julien, 
 
Greetings from Syncfusion support. 
 
We have validated your requirement in FileManager component. We have used session attribute in Blazor to send the variable from client to server side operations. But in Core, you can achieve it by passing root path as a variable in all File Operations. 
 
Please refer to the below code snippets. 
 
    public class HomeController : Controller 
    { 
        public PhysicalFileProvider operation; 
        public string basePath; 
        string root = "wwwroot\\Files\\Documents"; 
        …………….. 
        …………….. 
        public object FileOperations([FromBody] FileManagerDirectoryContent args) 
        { 
            this.operation.RootFolder(this.basePath + "\\" + this.root); 
            ……………. 
            ……………. 
        } 
        public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action, string user_name) 
        { 
            this.operation.RootFolder(this.basePath + "\\" + this.root); 
            …………….. 
            …………….. 
        } 
        public IActionResult Download(string downloadInput) 
        { 
            this.operation.RootFolder(this.basePath + "\\" + this.root); 
            …………….. 
            …………….. 
        } 
        public IActionResult GetImage(FileManagerDirectoryContent args) 
        { 
            this.operation.RootFolder(this.basePath + "\\" + this.root); 
            ………… 
            ………… 
         } 
     } 
  
Please find the sample from the below link for your reference.  
 
 
Please, check out the following links to know more about EJ2 File Manager component and its functionalities. 
 
 
 
 
Please let us know if you need further assistance. 
 
Regards, 
Indhumathy L 


Marked as answer

CL Csonka László June 26, 2024 01:32 PM UTC

Can I change the path to something which is not wwwroot/Files and so on for example C:\\Downloads?


Thank you!



SA SureshRajan Alagarsamy Syncfusion Team June 27, 2024 04:24 PM UTC

Hi Julien,


We have reviewed your query and understand that you are looking to set the root folder dynamically in the File Manager component which is located inside the C drive. To achieve this, you can pass the root folder path as a parameter in the “RootFolder” method in the FileManagerController.cs file.


Refer to the below code snippet for further reference.


[FileManagerController.cs]

public object FileOperations([FromBody] FileManagerDirectoryContent args)

{

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

    if (userDetails[0] == "DynamicUsers")

    {

        this.operation.RootFolder("C:\\" + "Folder");

    }

    ....

 

}


We have also attached a sample for your reference.


File Manager sample : Attached as zip folder.


Physical File Provider : Attached as zip folder.


Regards,
Suresh.


Attachment: CoreFileManagerPhysicalProvider_121156c.zip

Loader.
Up arrow icon