Make sure that any classes that relate to the attachment are fully disposed before trying to delete the file.
On 2 Sep, 18:16, JaffaB <[EMAIL PROTECTED]> wrote: > Hello All, > > I have a server based application which sends out emails with file > attachments. The problem I have is, that when I save the files in a > temp store to send them as attachments, and then try and delete them, > I get an exception error. > > My code is currently as follows: > > SmtpMail.Send(MailMsg) > System.Threading.Thread.Sleep(1000) > ' > ' Clear down the temp attachments > ' > For Inc As Integer = 0 To AttachmentList.Count - 1 > If File.Exists(AttachmentList(Inc)) Then > File.Delete(AttachmentList(Inc)) > End If > Next Inc > > And when it gets to the deletion of the files, I get the file in use > exception… > > Error occured as exception :- The process cannot access the file 'C: > \WINDOWS\system32\MyApp\Temp\TestDoc.doc' because it is being used by > another process. In MyApp Service > > As you can see, I have already tried the (crude) sleep option, but I > believe the MAIL.SEND is just queuing the mail up, and whatever thread > is then spawned still needs the attachment. > > What I really need is for send to wait to be completed before the code > continues, so the file is released and I can delete it. Otherwise, I > am going to fill up my disk with thousands of temp files. > > Any ideas would be appreciated > > Jaffa --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://cm.megasolutions.net/forums/default.aspx -~----------~----~----~----~------~----~------~--~---
