473,791 Members | 2,985 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 1902
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

1
1843
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
1079
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
2783
by: cj | last post by:
What's the parameter (like ?attachment) or something.
5
3737
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 works at all! if ($_FILES !="") { if ($_FILES<=0) { header("Location: /fileerror.php"); exit; }
2
1720
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
3248
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
5
2688
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 = $_POST; if(strlen($lengthCheck) < 1){ setcookie("shortLength", "No File Innput", time()+3600);
2
1088
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 secure connection or the client was not authenticated. The server response was: regor.lunarpages.com ESMTP MailEnable Service, Version: 0-2.37- denied access at 10/02/07 18:53:41 Please, help......i can't figure out second day what's going on
3
2073
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 obtain Exception Details: System.UnauthorizedAccessException: Access to the path '***' is denied.
2
4292
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 any thouhgts on how to get it in as an attachment. CODE: <?php ini_set(SMTP, "172.18.1.65");
0
9669
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
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
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
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2916
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.