I have created a webservice which does some processing from a DB into a CSV file and attempts to email that file. It is to be scheduled to run every day.
The problem I have is, at the moment on the web server I am deploying it to, the email sending fails and locks the file I am sending. Therefore the next time the process runs it fails due to the file still being locked. Is there anyway to make sure the file does not get locked even if the email fails?
I am using VB.NET 2.0 and VS2005.
Here is the code I use to send the mail if it helps:
myMail.From = myMailFrom
myMail.Subject = strSubject
If strPriority = "High" Then
myMail.Priority = MailPriority.High
myMail.Priority = MailPriority.Normal
myMail.IsBodyHtml = True
myMail.Body = strMessage
If Not AttachmentFiles Is Nothing Then
iCnt = AttachmentFiles.Count - 1
For i = 0 To iCnt
If FileExists(AttachmentFiles(i)) Then myMail.Attachments.Add(New Attachment(AttachmentFiles(i)))
Dim MailObj As New System.Net.Mail.SmtpClient
MailObj.Host = System.Configuration.ConfigurationManager.AppSettings("smtpHost")
Thanks for any help you can give me!