How to detect action on removing a file. (This is not the Clear button.)

Hello,

   I am still using the old 17.3.29 version but checking on the API looks like I couldn't find a method that is being called whenever the X button is clicked to remove a file. I'm talking about the removing of a single file not the Clear button that removes the entire selected file to be uploaded.

Thanks,

3 Replies 1 reply marked as answer

BC Berly Christopher Syncfusion Team October 2, 2020 12:02 PM UTC

Hi J, 
  
Greetings from Syncfusion support. 
  
We would like to inform you that we have provided remove event for the Uploader component. This event will be triggered when u clear the single file instead whole list. Please find the sample and code snippet below. 
  
<EjsUploader ID="UploadFiles" DropArea=".control-fluid"> 
    <UploaderEvents OnRemove="OnFileRemove"></UploaderEvents> 
    <UploaderAsyncSettings SaveUrl="https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save" RemoveUrl="https://aspnetmvc.syncfusion.com/services/api/uploadbox/Remove"></UploaderAsyncSettings> 
</EjsUploader> 
 
@code{ 
    public void OnFileRemove() 
    { 
        Console.WriteLine("File has been removed"); 
    } 
} 

  
  
Regards, 
Berly B.C 



AC Andy Corrigan replied to Berly Christopher August 11, 2021 02:15 PM UTC

Just to keep this up-to-date as it's still the first result on Google for anyone having issues; there is an optional parameter for this code that allows you to pick up the details of the file being removed if needs be. 


Snippet
<SfUploader @ref="uploader" MaxFileSize="@MaxSize" Files="uploadedFiles" AllowedExtensions=".doc, .docx, .pdf, .xls, .xlsx, .ppt, .pptx, .jpg, .jpeg, .bmp, .png" AllowMultiple="true" AutoUpload="true">
    <UploaderEvents ValueChange="OnFileUpload" OnRemove="OnFileRemove" />
</SfUploader>


Snippet
private async Task OnFileRemove(RemovingEventArgs args)
{
    foreach (var file in args.FilesData)
    {
        var fileName = file.Name;
        //Process file here
    }
}


BC Berly Christopher Syncfusion Team August 12, 2021 03:17 PM UTC

Hi Andy, 
  
We can send the optional parameter in the remove event with help of lambda expression in the Uploader component as mentioned below. 
  
  
 
<SfUploader @ref="uploader" MaxFileSize="@MaxSize"  AllowedExtensions=".doc, .docx, .pdf, .xls, .xlsx, .ppt, .pptx, .jpg, .jpeg, .bmp, .png" AllowMultiple="true" AutoUpload="true"> 
    <UploaderEvents ValueChange="OnFileUpload" OnRemove="@(e => OnFileRemove(e, "Date"))" /> 
</SfUploader> 
 
@code{ 
    SfUploader uploader; 
    public int MaxSize { get; set; } 
    public void OnFileUpload() 
    { 
 
    } 
    private async Task OnFileRemove(RemovingEventArgs args, string optionalParam) 
    { 
        foreach (var file in args.FilesData) 
        { 
            var fileName = file.Name; 
            //Process file here 
        } 
    } 
} 
 
  
  
Regards, 
Berly B.C 


Marked as answer
Loader.
Up arrow icon