.net - File is used by another process exception C# -
I have created an application that generates Excel files from information in the database, these files are saved in a folder on my HDD I
Then I attach files and send them via mail when I create another batch of files, then I delete old files and then make new ones .
My problem occurs when I have created a batch file and then sent them, and I want to create another batch, I can not remove one of the old files, because the mailing method There is still one of the Axel files
Here is my code:
Public Zero SendMailedFilesDKLol () {string [] sentFiles = Directory.GetFiles (some_folder); If (sent files.) ()> Gt; {System.Net.Mail.SmtpClient Client = New System.Net.Mail.SmtpClient ("ares"); System.Net.Mail.MailMessage msg = New System.Net.Mail.MailMessage (); Msg.From = new mail address ("system@lol.dk"); Msg.To.Add (new mail address ("lmy@lol.dk")); Msg.subject = "IBM Pado"; Msg Body = Sent Files Coat () + "The attached file (s) has been sent to the customer (customer) in question"; Msg.IsBodyHtml really =; Fresh (string file in sent file) {Attachment attachment = new attachment (file); Msg.Attachments.Add (attachment); } Client.Send (msg); }} I have tried to settle the client element, but he did not help.
Can anyone help me with it?
Both System.Net.Mail.MailMessage & amp; System.Net.Mail.SmtpClient are IDisposable classes. You can try the following, ( Net.NET.Mail.SmtpClient Clients = New System.Net.Mail.SmtpClient ("ares")) Mail. Mail Message msg = New System.Net.Mail.MailMessage ()) {msg.from = New MailAdd ("system@lol.dk"); Msg.To.Add (new mail address ("lmy@lol.dk")); Msg.subject = "IBM Pado"; Msg Body = Sent Files Coat () + "The attached file (s) has been sent to the customer (customer) in question"; Msg.IsBodyHtml = True; Fresh (string file in sent file) {Attachment attachment = new attachment (file); Msg.Attachments.Add (attachment); } Client.Send (msg); }}
Comments
Post a Comment