Additional parameter in SQLFileOpeations and Download

we are trying to send user name from UI to SQLFileOpeations and Download Events. Is it possible?

public object SQLFileOperations([FromBody] FileManagerDirectoryContent args,string userName)

5 Replies 1 reply marked as answer

SP Sowmiya Padmanaban Syncfusion Team May 11, 2020 08:34 AM UTC

Hi Mahesh,  
 
Greetings from Syncfusion support. 
 
We have checked your reported problem with FileManager component. Yes, it is possible to send the additional parameter from client-side to  the server-side API controller methods in the client-side events of FileManager component. 
 
SQL FileOperations and upload:  
 
You can send the Send additional parameter in upload and file operations in SQL using beforeSend event of FileManager component. 
 
Refer the belo2 code snippet. 
@Html.EJS().FileManager("filemanager").BeforeSend("beforeSend").BeforeDownload("beforeDownload").AjaxSettings(new Syncfusion.EJ2.FileManager.FileManagerAjaxSettings 
{ 
}).Render() 
 
<script> 
    function beforeSend(args) { 
         var data = JSON.parse(args.ajaxSettings.data);  
          if (args.action == "Upload") {  
            // Allow custom data for upload operations   
            data.push({ 'username': "user1" });  
            args.ajaxSettings.data = JSON.stringify(data);  
         } 
         else { 
          // Add custom parameter column  
            data["username"] = "user1";  
          // Add custom parameter in ajax settings  
            args.ajaxSettings.data = JSON.stringify(data);  
         } 
    } 
 
You can add the custom class in controller part and use the class in fileOperations.  
 
    public class FileManagerDirectoryContent1 
    {  
        public string username { get; set; } 
        public FileManagerDirectoryContent[] Data { get; set; } 
        public bool ShowHiddenItems { get; set; } 
   } 
public object SQLFileOperations([FromBody] FileManagerDirectoryContent1 args) 
        { 
            if ((args.Action == "delete" || args.Action == "rename") && ((args.TargetPath == null) && (args.Path == ""))) 
            { 
                FileManagerResponse response = new FileManagerResponse(); 
                response.Error = new ErrorDetails { Code = "403", Message = "Restricted to modify the root folder." }; 
                return operation.ToCamelCase(response); 
            } 
} 
 
Refer the below screenshot.  
 
 
 
Download : 
 
You can send the addition parameters od Download operations using beforeDownload operations. 
 
Refer the below code snippet. 
 
@Html.EJS().FileManager("filemanager").BeforeSend("beforeSend").BeforeDownload("beforeDownload").AjaxSettings(new Syncfusion.EJ2.FileManager.FileManagerAjaxSettings 
{ 
}).Render() 
<script> 
    function beforeDownload(args) { 
         var includeCustomAttribute = args.data; 
         includeCustomAttribute.username = "user1"; 
         args.data = includeCustomAttribute; 
   } 
</script> 
 
Refer the below screenshot. 
 
 
 
 
For your reference, we have prepared a sample with above solution, which will help you meet your expected requirement. 
 
 
 
Note: Run the service and refer the local host URL in FileManager sample. 
 
Refer the below similar forum for your requirement. 
 
 
To know more about the FileManager component, refer the below link. 
 
 
 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 


Marked as answer

MM Mahesh Machina May 13, 2020 01:41 PM UTC

Thank You


SP Sowmiya Padmanaban Syncfusion Team May 14, 2020 07:10 AM UTC

Hi Mahesh,  
  
Most Welcome. We are happy to hear that our provided meet your requirement. Please contact us, if you need any help from us. We will happy to assist you. 
  
Regards,  
Sowmiya.P 
  
  



KP Kaustubh Palande July 20, 2022 01:35 AM UTC

Hello, Thanks for the update but I would like to know how to avoid passing those parameters using " beforeSend " function of component.html file ? because that will be available in view source if unwanted user wants to hack it.



SS Sivakumar ShunmugaSundaram Syncfusion Team July 20, 2022 04:27 PM UTC

Hi Kaustubh,


Greetings from Syncfusion support.


As per the shared details, we understand that you need to avoid passing those parameters using the "beforeSend " event. In our previous update, we have sent JWT token from client end to perform customizations at server end. For getting client-side login user details in server side without sending it from client end, we suggest you refer to refer the below blob to get the details directly at server end and achieve your requirements.


Link 1: https://stackoverflow.com/questions/1240373/how-do-i-get-the-current-username-in-net-using-c#:~:text=GetCurrent().,the%20user%27s%20Windows%20logon%20name.


Link 2: https://docs.microsoft.com/en-us/dotnet/api/system.environment.username?view=net-6.0


Please get back to us, if you need any further assistance.


Regards,

Sivakumar S


Loader.
Up arrow icon