473,466 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1888
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

1
by: ohb | last post by:
Hello, is someone have a example of c# source of a service which is reading a attach file of an email.? Thank you. OHB.
4
by: Robert | last post by:
How can I read a file in, make the contents of the file the body of an email message and then email it? I want to read an HTML file in and send an HTML formatted email message.
12
by: cj | last post by:
What's the parameter (like ?attachment) or something.
5
by: Jefferis NoSpamme | last post by:
Hi all, I'm trying to limit the file size of an image submission and I keep running into various problems. I've got most of it working, but I'm stumped and I have a basic question as to WHY this...
2
by: ptkumar | last post by:
Hi everybody, I am generating pdf file but how to send the pdf file to required email id.. any body can help this.. Thnxs..
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...
5
Markus
by: Markus | last post by:
I'm developing a small image hosting project (not commercial just a project to test my php abilities) and i want to check that the user has entered a file the code: <?php $lengthCheck =...
2
by: dkate777 | last post by:
Is anybody know where to look and what to check? My sent email work fine from several forms, but in one day, everything stop working and i got this error message: The SMTP server requires a...
3
by: Steph | last post by:
hello, i ve a probleme when deleting a directory and when i want create file immediatly after. 1) Directory.Delete(myPath, true); 2) TextWriter sw = new StreamWriter(myPath +"test.aspx"); i...
2
by: Erik Witkop | last post by:
So I have been trying to get this to work all day. I can't get a local file on my web server to attach to an email. Right now I have it printing out in the body of the email. Please help me with...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.