473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

File busy after sent via email

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
May 3 '07 #1
6 3231
freaky look at the post right above yours, i just asked the same thing!

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:u1****************@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

May 3 '07 #2
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
May 4 '07 #3
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

"Andrew Morton" <ak*@in-press.co.uk.invalidwrote in message
news:u0**************@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

May 5 '07 #4
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
May 8 '07 #5
Appears that its the program. As it only happens after program sends the
email and not before.

Regards

"Andrew Morton" <ak*@in-press.co.uk.invalidwrote in message
news:O6**************@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

May 8 '07 #6
John wrote:
Appears that its the program. As it only happens after program sends the
email and not before.

Regards

"Andrew Morton" <ak*@in-press.co.uk.invalidwrote in message
news:O6**************@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


Call "System.Net.Mail.Attachment.Dispose()" after send mail.
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
May 9 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Google Mike | last post by:
I have PHP version 4.2.2 that ships with RH9. I want to have it write to a file like this: function WriteLog($sLogFile, $sMsg) { if (substr($sLogFile,1,1) != '/') { $sLogFile =...
6
by: Ken Varn | last post by:
Sometimes when I try to close my managed C++ application, the following dialog displays in Win 2000 Pro: The title of the dialog is "Server Busy". The message is "This action cannot be completed...
6
by: Omid | last post by:
Hi. I have problems when I try to redirect everything that is sent to cout to a file. I have one piece of code that works and one that does not work. The only difference is which headers I use....
6
by: Alex | last post by:
I have Office Xp Professional loaded. In Access the Make MDE file option on the menu is greyed out. Is it possible to create an MDE file without the developer version? Why is the option on the menu...
10
by: x.meglio | last post by:
I'm looking for simple class to get web-page with some members to control execution: 1. string Get(string URL) - just get html-page 2. bool Busy - return true while object loading resource 3....
0
by: karen987 | last post by:
Please could someone help me with this code? The problem appears to be a simple one, but i'm not html or ASP literate and need to modify the below code to add 2 things. First a bit about the...
6
by: John | last post by:
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...
9
by: John Kotuby | last post by:
Hi all... While looking around for tools to create Excel files from either HTML pages or the Data I use to assemble them, I got an interesting response from a vendor. I have looked at Apose, and...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.