I have an upload button on my website and that upload button saves a file the user selected on my hard drive (for now), and it also saves the name (with Guid.NewGuid) + a friendly name (actual name) up in the database.
The file is saved at Content/Usercontent (the Guid.NewGuid name), but what I want, is that when you delete a row from your database, that the file in the map Content/Usercontent is also deleted, how do I do this with ASP.NET MVC
EDIT: Why was I voted down? Atleast tell me what I should improve on my question.
As long as you have hooked into the event called OnDelete (for example) then you could sync this with routine that deletes that associated file.
I would create a class that is the sole manager for adding and removing files from the database. What I would do when you upload a file is then call the class
documentMgr.Save(string fileName, string serverPath, byte[] fileContents).On the DocumentManager class I would create a event called FileDeleted where the deegate takes the folowing args (
object sender, FileEventArgs fileArgs) and create an event handler on that class calledOnFileDeleted(object sender, FileEventArgs fileArgs)and raise the OnFileDeleted event when the DocumentManager.DeleteDocument(string name, string whatever) is called.The event handler can be handled from an where then (if it event is public).
You can hook up the event in the constructor of the DocumentManager then the call with dea with the deleting of the file automatically and by using events, you can opt to do more and extend the functionality later.
Let me know how you get on