Yous to be clear:
1) You put your image in the folder
2) You insert the record with some metadata
and the image binary data
and you keep the image in the folder
3) When you delete the record you want to delete the image from the folder too?
Correct?
Questions:
- Why do you keep duplicate of the image data?
- Why don't you delete from the folder after you stored it in the database?
- What have you considered so far?
Actually you have several alternatives:
A) use
FILESTREAM feature[
^], and you gain a lot: no duplication, quick access, you have the record and the file on the filesystem and they are automatically linked
B) use OLE Automation from SQL Server. See:
http://www.kodyaz.com/articles/delete-file-from-sql-server-xp-cmdshell-ole-automation-procedures.aspx[
^] and
http://kb.hyve.com/wiki/DeleteFilesInSQLServer[
^]
C) Make a
CLR procedure[
^] for this purpose
D) Make the "consumer/client" that is responsible for storing the file to delete on it's behalf. Who told you that you need to do that from within sql server?
Personally I would consider alternative A! It is a great feature!