Results 1 to 6 of 6

Thread: [RESOLVED] system.IO.IOException

Threaded View

  1. #1

    Thread Starter
    Lively Member viper5646's Avatar
    Join Date
    Feb 2009
    Location
    kitchener Ontario
    Posts
    90

    Resolved [RESOLVED] system.IO.IOException

    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

    Code:
    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")
                System.IO.File.Delete(AttDir & fileName & ".pdf")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Sub
    Last edited by viper5646; Dec 29th, 2011 at 11:26 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width