|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File busy after sent via emailI am emailing a text file as attachment via the below code. The problem is that after the file has been emailed, it becomes locked and can not be accessed by further code such as IO.File.AppendAllText(FileName, Content) which gives the error 'file is in use by another process' or something similar. How can I release the file after it has been emailed or email it in a way that it does not get locked? Many Thanks Regards = Code Below =========================== Dim Msg As String Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo)) MailMsg.BodyEncoding = System.Text.Encoding.Default MailMsg.Subject = strSubject.Trim() MailMsg.Body = strMessage.Trim() & vbCrLf MailMsg.Priority = MailPriority.High MailMsg.IsBodyHtml = True MailMsg.Attachments.Add(New System.Net.Mail.Attachment(Attachment)) Dim SmtpMail As New SmtpClient SmtpMail.Host = My.Settings.SMTPServer SmtpMail.Port = 25 SmtpMail.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network SmtpMail.Send(MailMsg) SmtpMail = Nothing MailMsg = Nothing freaky look at the post right above yours, i just asked the same thing!
Show quoteHide quote "John" <John@nospam.infovis.co.uk> wrote in message news:u1ROc%23bjHHA.1624@TK2MSFTNGP02.phx.gbl... > Hi > > I am emailing a text file as attachment via the below code. The problem is > that after the file has been emailed, it becomes locked and can not be > accessed by further code such as IO.File.AppendAllText(FileName, Content) > which gives the error 'file is in use by another process' or something > similar. How can I release the file after it has been emailed or email it > in a way that it does not get locked? > > Many Thanks > > Regards > > > = Code Below =========================== > > Dim Msg As String > Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New > MailAddress(strTo)) > > MailMsg.BodyEncoding = System.Text.Encoding.Default > MailMsg.Subject = strSubject.Trim() > MailMsg.Body = strMessage.Trim() & vbCrLf > MailMsg.Priority = MailPriority.High > MailMsg.IsBodyHtml = True > MailMsg.Attachments.Add(New System.Net.Mail.Attachment(Attachment)) > > Dim SmtpMail As New SmtpClient > > SmtpMail.Host = My.Settings.SMTPServer > SmtpMail.Port = 25 > SmtpMail.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network > SmtpMail.Send(MailMsg) > SmtpMail = Nothing > MailMsg = Nothing > John wrote:
> I am emailing a text file as attachment via the below code. The If it's any help, you can find which process has the lock on the file by > problem is that after the file has been emailed, it becomes locked > and can not be accessed by further code such as > IO.File.AppendAllText(FileName, Content) which gives the error 'file > is in use by another process' or something similar. How can I release > the file after it has been emailed or email it in a way that it does > not get locked? using unlocker from http://ccollomb.free.fr/unlocker/ Andrew that really doesnt answer or question on why the attachment process in
net.mail locks files and doesnt release the lock after attaching and sending Show quoteHide quote "Andrew Morton" <a**@in-press.co.uk.invalid> wrote in message news:u0oo2rijHHA.1388@TK2MSFTNGP05.phx.gbl... > John wrote: >> I am emailing a text file as attachment via the below code. The >> problem is that after the file has been emailed, it becomes locked >> and can not be accessed by further code such as >> IO.File.AppendAllText(FileName, Content) which gives the error 'file >> is in use by another process' or something similar. How can I release >> the file after it has been emailed or email it in a way that it does >> not get locked? > > If it's any help, you can find which process has the lock on the file by > using unlocker from > http://ccollomb.free.fr/unlocker/ > > Andrew > Smokey Grindel wrote:
> that really doesnt answer or question on why the attachment process in Ah, but is it the OP's program or the OS which has the lock on the file?> net.mail locks files and doesnt release the lock after attaching and > sending Andrew Appears that its the program. As it only happens after program sends the
email and not before. Regards Show quoteHide quote "Andrew Morton" <a**@in-press.co.uk.invalid> wrote in message news:O6cq7LUkHHA.3816@TK2MSFTNGP02.phx.gbl... > Smokey Grindel wrote: >> that really doesnt answer or question on why the attachment process in >> net.mail locks files and doesnt release the lock after attaching and >> sending > > Ah, but is it the OP's program or the OS which has the lock on the file? > > Andrew > John wrote:
Show quoteHide quote > Appears that its the program. As it only happens after program sends the Call "System.Net.Mail.Attachment.Dispose()" after send mail.> email and not before. > > Regards > > "Andrew Morton" <a**@in-press.co.uk.invalid> wrote in message > news:O6cq7LUkHHA.3816@TK2MSFTNGP02.phx.gbl... >> Smokey Grindel wrote: >>> that really doesnt answer or question on why the attachment process in >>> net.mail locks files and doesnt release the lock after attaching and >>> sending >> Ah, but is it the OP's program or the OS which has the lock on the file? >> >> Andrew >> > > The "Attachment" object will lock the file until "Dispose". If you do not call "Dispose()" explicitly, the file just will be unlocked after garbage collection. -- Jacky Kwok jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
is there a control that displays a multi-column array of rectangles
Is This Overkill? Talking with USB GPS in VB.Net Designing Email Msg. Listing properties of an object Checking db connection open status Help Converting Some C# Code to Visual Basic... Datagrid Multiple Select Versioning problem Database closing problem |
|||||||||||||||||||||||