We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cannot remove files via custom method

Thread ID:

Created:

Updated:

Platform:

Replies:

146215 Jul 25,2019 08:48 PM UTC Jul 29,2019 07:14 AM UTC Blazor 3
loading
Tags: File Upload
Ivan Petrov
Asked On July 25, 2019 08:48 PM UTC

Hello,

I am trying to remove files by attaching a method to the OnRemove delegate of a file upload object. It looks like this.fileUploadObj.OnRemove = OnFileRemove; . However, the method OnFileRemove is not invoked when I remove a file. The same issue is not valid for the OnUploadtStart property.

Berly Christopher [Syncfusion]
Replied On July 26, 2019 01:36 PM UTC

Hi Krasimir, 
  

Greetings from Syncfusion support.  

  
While checked the reported query, we suspect that you have bind the success and remove event on the custom method in the “OnInit” method. In this case, our Blazor component will not render and Uploader object will be null. This may be the root cause of the reported issue at your end. So, we suggest you to bind the custom method for the success and removing event in “OnAfterRender” as mentioned in the below code example.  

  
[index.razor

<EjsUploader @ref="fileUploadObj" ID="UploadFiles"> 
    <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings> 
</EjsUploader> 
<div> 
    <p>Uploaded File Name is: @FileName</p> 
    <p>Removed File Name is: @Removing</p> 
</div> 
@code{ 
EjsUploader fileUploadObj; 
public string FileName; 
public string Removing; 
public void OnSuccess(object args) 
{ 
    //Deserialized the success event args using Newton soft. 
    SuccessEventArgs eventArgs = JsonConvert.DeserializeObject<SuccessEventArgs>(args.ToString()); 
    // Assign the file name in the variable 
    FileName = eventArgs.File.Name; 
    // To reflect the DOM content 
    this.StateHasChanged(); 
} 
//Success event args class. 
public class SuccessEventArgs 
{ 
    public object E { get; set; } 
    public FileInfo File { get; set; } 
    public string StatusText { get; set; } 
    public string Name { get; set; } 
    public string Operation { get; set; } 
    public ResponseEventArgs Response { get; set; } 
} 
 
public class ResponseEventArgs 
{ 
    public string Headers { get; set; } 
    public object ReadyState { get; set; } 
    public object StatusCode { get; set; } 
    public string StatusText { get; set; } 
    public bool withCredentials { get; set; } 
} 
public void OnFileRemove(RemovingEventArgs args) 
{ 
    Removing = args.FilesData[0].Name; 
    StateHasChanged(); 
} 
 
 
protected override void OnAfterRender() 
{ 
    this.fileUploadObj.OnRemove = this.OnFileRemove; 
    this.fileUploadObj.Success = this.OnSuccess; 
} 
} 


  
Please find the sample from the below link. 

 
  
Regards, 
Berly B.C 


Ivan Petrov
Replied On July 26, 2019 02:13 PM UTC

My OnRemove method is bound inside the OnAfterRender method. Could you check if it works for you? Thank you in advance.

Berly Christopher [Syncfusion]
Replied On July 29, 2019 07:14 AM UTC

Hi Krasimir, 
  

We would like to inform you that, In our last update we have bind the OnRemove method inside the OnAfterRender method. Can you please check the below code example and let us know if you need any other customization that will help us to check and provide the prompt solution? 

  
[index.razor

<EjsUploader @ref="fileUploadObj" ID="UploadFiles"> 
    <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings> 
</EjsUploader> 
<div> 
    <p>Uploaded File Name is: @FileName</p> 
    <p>Removed File Name is: @Removing</p> 
</div> 
@code{ 
EjsUploader fileUploadObj; 
public string FileName; 
public string Removing; 
protected override void OnAfterRender() 
{ 
    this.fileUploadObj.OnRemove = this.OnFileRemove; 
    this.fileUploadObj.Success = this.OnSuccess; 
} 
public void OnFileRemove(RemovingEventArgs args) 
{ 
    Removing = args.FilesData[0].Name; 
    StateHasChanged(); 
} 
public void OnSuccess(object args) 
{ 
    //Deserialized the success event args using Newton soft. 
    SuccessEventArgs eventArgs = JsonConvert.DeserializeObject<SuccessEventArgs>(args.ToString()); 
    // Assign the file name in the variable 
    FileName = eventArgs.File.Name; 
    // To reflect the DOM content 
    this.StateHasChanged(); 
} 
//Success event args class. 
public class SuccessEventArgs 
{ 
    public object E { get; set; } 
    public FileInfo File { get; set; } 
    public string StatusText { get; set; } 
    public string Name { get; set; } 
    public string Operation { get; set; } 
    public ResponseEventArgs Response { get; set; } 
} 
 
public class ResponseEventArgs 
{ 
    public string Headers { get; set; } 
    public object ReadyState { get; set; } 
    public object StatusCode { get; set; } 
    public string StatusText { get; set; } 
    public bool withCredentials { get; set; } 
} 
} 

 
  
Regards, 
Berly B.C 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon