Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to delete the attachment file which is stored in a temp location after sending the mails. I am using the following code but it is giving the error, as
The process cannot access the file "path" because it is being used by another process.The process cannot access the file

File.delete(locpath);

Can anyone help me in solving this.I should delete all the attachment files stored in that location.
thanks
Posted
Updated 8-Jun-11 1:55am
v2

1 solution

Hi,
try disposing the email message, thus forcing the CLR to unlock the file, and continue with its deletion.
try
 {
      smtp.Send(emailMsg);
 }
 catch ...
 finally
 {
      emailMsg.Dispose();
 }
....
File.Delete(attachment);


Regards
 
Share this answer
 
Comments
Petros Romani 22-Jun-11 9:59am    
Thanks a lot! I was facing the same problem and disposing the email message let me delete the attachment included within the email.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900