This is only part solution, because You need to find how you will take files from mediaa library by its url, and then delete them. You can find this in
Media library solution
public partial class CMSModuleLoader
/// Attribute class that ensures the loading of custom handlers.
private class CustomTableEventsAttribute : CMSLoaderAttribute
/// The system executes the Init method of the CMSModuleLoader attributes when the application starts.
public override void Init()
// Assigns custom handlers to events
private void Delete_Before(object sender, ObjectEventArgs e)
/* do your work here, you need to take media files from media library which are
in your custom table and to delete the files from media library, before you
delete the custom table.