Problem deleting mail attachment
-
Hi all, i m sending mails using Asp.net 2.0 Here is my code Sub SendMail() Dim msg As New MailMessage() Dim attach_file1 As String = String.Empty Dim strfilename As String = String.Empty Dim strpath As String = Request.ApplicationPath & "/" & "Attachments" & "/" strfilename = Path.GetFileName(UploadCV.PostedFile.FileName) UploadCV.PostedFile.SaveAs(Server.MapPath(strpath & strfilename)) Dim attach As New Attachment(Server.MapPath(strpath & strfilename)) msg.Attachments.Add(attach) attach_file1 = strfilename Dim smtpclnt As New SmtpClient() Dim ds1 As New DataSet() ds1 = CType(Session("Dataset"), DataSet) msg.Subject = "You have successfully applied for the post of " & ds1.Tables(0).Rows(0).Item(2).ToString() msg.Body = "Hi all" 'msg.To.Add(ds1.Tables(0).Rows(0).Item(9)) msg.To.Add("somemail@gmail.com") msg.From = New MailAddress(Session("emailid").ToString()) smtpclnt.Send(msg) If attach_file1 <> "" Then File.Delete(Server.MapPath(strpath & strfilename)) End If End Sub but it gives me exception at File.Delete(Server.MapPath(strpath & strfilename)) and it says The process cannot access the file (filepath) because it is being used by another process. any idea abt this error?
modified on Sunday, July 17, 2011 2:38 PM