Hi all
In the following Sub I'm sending an Attachment when the email has been sent I would like to delete the attachment but I get an system.IO.IOException Error. the file I'm trying to delete is being used by another process.
How can I detect if the process has finished.
Thanks
Happy New Year to everyone
Private Sub SendMail()
Try
Dim cfiAttach As Net.Mail.Attachment
Dim Attacmentfile As String = AttDir & fileName & ".pdf"
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential(diaSettings.txtMail_User.Text, diaSettings.txtMail_Pass.Text)
SmtpServer.Port = smtpPrt
SmtpServer.Host = SmtpHst
mail = New MailMessage()
mail.From = New MailAddress(Mail_user)
mail.To.Add(Mail_TO)
' mail.Bcc.Add(BBC_MailTO)
mail.Subject = fileName
mail.Body = ""
cfiAttach = New Attachment(Attacmentfile)
If File.Exists(Attacmentfile) Then
cfiAttach = New Attachment(Attacmentfile)
mail.Attachments.Add(cfiAttach)
Else
MsgBox("Attachment Not Found")
End If
SmtpServer.Send(mail)
MsgBox("Sent")
[U]System.IO.File.Delete(AttDir & fileName & ".pdf")[/U]
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub