how to pass custom data to Upload event from client side

We are using SQL provider

is it possible to send additional data to this method public IActionResult SQLUpload(string path, IList<IFormFile> uploadFiles, string action, string data)
 from client side(beforeSend event/ any other)

public IActionResult SQLUpload(string path, IList<IFormFile> uploadFiles, string action, string data,string custom1,string custom2)

Please give response ASAP. Thank you

5 Replies

SP Sowmiya Padmanaban Syncfusion Team February 12, 2020 09:05 AM UTC

Hi Mahesh,  
 
Greetings from Syncfusion support. 
 
We have checked your reported query that how to pass the custom parameter in upload operation. Yes, it is possible to sent it in beforeSend() event.  
 
Refer the below code snippet to sent the custom parameter in client side. 
 beforeSend: function(args) { 
    if (args.action == "Upload") { 
      var data = JSON.parse(args.ajaxSettings.data); 
      // Add custom parameter column 
      data.push({ custom: "1" }); 
      // Add custom parameter in ajax settings 
      args.ajaxSettings.data = JSON.stringify(data); 
    } 
  } 

You can also receive the custom parameter in your server side. Refer the below screenshot. 
 
 
After that you can use the custom parameter based on your requirement. For your reference, we have attached a service and sample link. 
 
 
 
Please let us know, if you need any further assistance on this. 
 
Regards,  
Sowmiya.P 



UN Unknown Syncfusion Team February 12, 2020 10:32 AM UTC

Thanks a lot Sowmiya.

Could you please check on the below query 

we have added 2 more columns(ExpiryDate,Author) in product table and we tried to change your search logic in such a way that it should search on Name,ExpiryDate,Author columns

SqlDataReader reader = (new SqlCommand("select * from " + this.TableName + " where Name like '" + searchString.Replace("*", "%") + "' OR ExpiryDate like '" + searchString.Replace("*", "%") + "' OR Author like '" + searchString.Replace("*", "%") + "' AND ItemID IN(" + string.Join(", ", availableFiles.Select(f => "'" + f + "'")) + ")", sqlConnection)).ExecuteReader();

This query works first time, when we enter the same sear string again it displays all the files in that folder. Any idea? Please let us know


SP Sowmiya Padmanaban Syncfusion Team February 13, 2020 09:49 AM UTC

Hi Mahesh,  
 
We have checked your reported query that search operation is not performed properly for custom attribute. Based on your requirement, we have added a ReviewNumber as a custom field and perform the search operation based on the custom field. 
 
While uploading you can send the custom field in beforeSend() event and add the field in uploadQuery() method. Refer the below code snippet. 
 
[Js]     
function beforeSend(args) { 
        if (args.action == "Upload") { 
            var data = JSON.parse(args.ajaxSettings.data); 
            // Add custom parameter column  
            data.push({ reviewNumber: "1" }); 
            // Add custom parameter in ajax settings  
            args.ajaxSettings.data = JSON.stringify(data); 
        } 
    } 
 
[C#] 
public void UploadQuery(string filename, string contentType, byte[] bytes, string parentId, string reviewNumber) 
        { 
command.Parameters.Add(new SqlParameter("@ReviewNumber", reviewNumber)); 
} 
 
If you want to perform the search based on custom attribute, you can override the search operation in server side and perform the search based on custom attribute. 
 
public object FileOperations([FromBody] FileManagerDirectoryContent args) 
        {   
        switch (args.Action) 
            { 
                case "search": 
                    return this.search(args); 
            } 
            return null; 
        } 
public object search(FileManagerDirectoryContent args) 
        { 
            FileResponse readResponse = new FileResponse(); 
            try 
            { 
                // In the below serach operation you can perform the search based on review number 
                var value = this.operation.Search(args.Path, args.SearchString, args.ShowHiddenItems, args.CaseSensitive, args.Data); 
                 // Tn the below class, you can add the review number as a additional attribute. 
                DirectoryContent cwd = new DirectoryContent(); 
            } 
} 
 
// New property ReviewNumber is added to DirectoryContent class to perform this customization 
public class DirectoryContent 
    { 
        public string ReviewNumber { get; set; } 
 
        public string Path { get; set; } 
    } 
 
public FileManagerResponse Search(string path, string searchString, bool showHiddenItems, bool caseSensitive, params FileManagerDirectoryContent[] data) 
        { 
         // Search the item based on Review number 
         SqlDataReader reader = (new SqlCommand("select * from " + this.TableName + " where ReviewNumber like '" + searchString.Replace("*", "%") + "' AND ItemID IN(" + string.Join(", ", availableFiles.Select(f => "'" + f + "'")) + ")", sqlConnection)).ExecuteReader(); 
                    while (reader.Read()) 
                    { 
                        searchData = new FileManagerDirectoryContent 
                        { 
                           // Add the review number field in serach data. 
                            ReviewNumber = reader["ReviewNumber"].ToString(), 
                            Id = reader["ItemId"].ToString().Trim() 
                        }; 
                         
                    }      
} 
 
If you want to display the reviewNumber column in DetailsView, you can override the getFiles method. We have considered this requirement too in the below attached sample. 
 
 
Note: It is mandatory to add the custom field in SQL Tables. 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 



UN Unknown Syncfusion Team February 13, 2020 02:22 PM UTC

Thanks.

I have acheived my requirement already, my approach also very similar to yours


SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team February 14, 2020 04:17 AM UTC

Hi Mahesh, 
 
We are happy to hear that you have achieved your expected requirement. Please contact us if you need any help from us. We will be happy to help you. 
 
Regards, 
Shameer Ali Baig S. 


Loader.
Up arrow icon