devhammed
Is there any way to delete old image/attachments when deleting or updating records??
@justgkp I typically use a File model for attaching things like images to models since it will allow me to store extra metadata like width, height, duration (for videos), page numbers (PDF) etc.
But what matters is that you can call the "using" method on Edit action which allows you to customize the update process, this will also give you the ability to check if there is a previous image and delete it after attaching the new one to the model.
Note that the uploaded file property will be the path string as it would have been saved already according to what you have configured.
And it will be null if the file has been detached in the form so you can also delete the previous image file in that case to persist the removal.
Below is an example code from one of the projects I have worked on:
7 replies