Forum Moderators: open
Everytime I try this I get the following error:
The process cannot access the file '<filepath>' because it is being used by another process.
Even when I attempt to delete the file through an ftp client, I get this error.
My code snippet follows ---------------------
'--- Get the uploaded resume file.
Dim fileName As String = GetFileName(resumeFileUpload.PostedFile.FileName)
Try
resumeFileUpload.PostedFile.SaveAs("C:\PATH GOES HERE" + fileName)
Dim mailAttachment = New Attachment("C:\PATH GOES HERE" + fileName)
mailMessage.Attachments.Add(mailAttachment)
mailSmtp.Send(mailMessage)
Catch Exp As Exception
errorLabel.text = "We're sorry, but there was an error."
Finally
System.IO.File.Delete("C:\PATH GOES HERE" + fileName)
End Try
Code Snippet Ends -----------------------------
I would greatly appreciate any help with this issue.
I was trying to delete the uploaded file, but it was locked and being used by MailMessage object.
Just before my delete statement, I added the following:
mailMessage.Dispose()
And the file is unlocked and deleted from the system.
I hope this is of help to someone...