473,781 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ 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.AppendA llText(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(str From.Trim()), New
MailAddress(str To))

MailMsg.BodyEnc oding = System.Text.Enc oding.Default
MailMsg.Subject = strSubject.Trim ()
MailMsg.Body = strMessage.Trim () & vbCrLf
MailMsg.Priorit y = MailPriority.Hi gh
MailMsg.IsBodyH tml = True
MailMsg.Attachm ents.Add(New System.Net.Mail .Attachment(Att achment))

Dim SmtpMail As New SmtpClient

SmtpMail.Host = My.Settings.SMT PServer
SmtpMail.Port = 25
SmtpMail.Delive ryMethod = Net.Mail.SmtpDe liveryMethod.Ne twork
SmtpMail.Send(M ailMsg)
SmtpMail = Nothing
MailMsg = Nothing
May 3 '07 #1
6 3247
freaky look at the post right above yours, i just asked the same thing!

"John" <Jo**@nospam.in fovis.co.ukwrot e in message
news:u1******** ********@TK2MSF TNGP02.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.AppendA llText(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(str From.Trim()), New
MailAddress(str To))

MailMsg.BodyEnc oding = System.Text.Enc oding.Default
MailMsg.Subject = strSubject.Trim ()
MailMsg.Body = strMessage.Trim () & vbCrLf
MailMsg.Priorit y = MailPriority.Hi gh
MailMsg.IsBodyH tml = True
MailMsg.Attachm ents.Add(New System.Net.Mail .Attachment(Att achment))

Dim SmtpMail As New SmtpClient

SmtpMail.Host = My.Settings.SMT PServer
SmtpMail.Port = 25
SmtpMail.Delive ryMethod = Net.Mail.SmtpDe liveryMethod.Ne twork
SmtpMail.Send(M ailMsg)
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.AppendA llText(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.inv alidwrote in message
news:u0******** ******@TK2MSFTN GP05.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.Append AllText(FileNam e, 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.inv alidwrote in message
news:O6******** ******@TK2MSFTN GP02.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.inv alidwrote in message
news:O6******** ******@TK2MSFTN GP02.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.Mai l.Attachment.Di spose()" 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_DO T_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
5802
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 = realpath(dirname($_SERVER)) . $sLogFile; } `echo "$sMsg" >> $sLogFile`;
6
16958
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 because the other program is busy. Choose 'Switch to' to activate the busy program and correct the problem." I don't know why this is displayed. I would prefer to disable the display of this message if possible. My app needs to be able to...
6
21067
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. What the code does: * First writes "This is sent to prompt" to prompt.
6
2966
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 if I can't use it? Alex
10
1952
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. Stop() to stop execution There are problems to use HTTPWebRequest.GetResponse as it lock main thread. any ideas?
0
1421
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 website: It's a news website, which has talkback, where the public register to post comments. One of the options in the comments is for the commentator to leave an email icon, if they want private emails from other readers. The initial email is sent...
6
1902
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 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
9
1405
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 may end up using their product. I am also looking at the capability of SQL Server 2005 reporting services to produce multi-worksheet workbooks. However, a vendor that does HTML to PDF conversion asked me why I have not used Office Open XML...
4
3875
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 am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7486
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
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 we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.