Hi Ishan,
Thanks for contacting Syncfusion support.
We suggest you to use ejUploadBox for image upload where we have an in-built option to delete the uploaded file. Once the file is uploaded, you will get a delete icon as shown below to remove the uploaded file
On clicking this delete icon, the file will be deleted from the saved location. Delete action is performed from RemoveUrl controller action. Refer to the following code
|
<div class="posupload">
@Html.EJ().Uploadbox("UploadDefault").SaveUrl(@Url.Action("SaveDefault")).RemoveUrl(@Url.Action("RemoveDefault"))
</div>
public ActionResult RemoveDefault(string[] fileNames)
{
foreach (var fullName in fileNames)
{
var fileName = Path.GetFileName(fullName);
var physicalPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
}
return Content("");
} |
The above code can also be used on separate button click action for deleting the files in corresponding path.
We have attached a sample for your reference in the following link
Refer to the following links for more details on Button and UploadBox controls.
Please let us know if you need further assistance.
Regards,
Keerthana.