Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with difference between System.Web.Mail and System.Net.Mail in using attachments

Reply
Thread Tools

Problem with difference between System.Web.Mail and System.Net.Mail in using attachments

 
 
Brad
Guest
Posts: n/a
 
      04-25-2006
I have a web .Net app which sends emails with attachments. After the email
is sent I clean up aftermyself and delete the attachments from disk. In
upgrading to .Net 2 I changed the email logic from using system.web.mail to
system.net.mail (of course vs is telling me system.web.mail is obsolete).
In .Net 1.1, the files deleted with no problem but in .Net 2 when I attempt
to delete I receive

The process cannot access the file ...' because it is being used by another
process.

If I change the code back to using system.web.mail I can delete the files.
So it would appear that something about the mail object, using
system.net.mail, keeps the file in use. I found the same is true if I
attempt to overwrite the files using something like File.Copy(from,to,
true). Why in .Net 2 would the disk files still be in use...or at least
how can they be released?

Below is snip of code, both the 1.1 and 2.0 version.

..Net 1.1 code
============================
Dim mailObj As New System.Web.Mail.MailMessage()
With mailObj
.From = fromName
.To = toName
.Body = body.ToString
.Priority = MailPriority.High
.Subject = "Test"
.BodyFormat = Mail.MailFormat.Html
.Attachments.Add(New
System.Web.Mail.MailAttachment(attachment1Name))
.Attachments.Add(New
System.Web.Mail.MailAttachment(attachment2Name))

End With

System.Web.Mail.SmtpMail.SmtpServer = server
System.Web.Mail.SmtpMail.Send(mailObj)

File.Delete(attachment1Name)
File.Delete(attachment2Name)
========================================


..Net 2.0 code
========================================
Dim mailObj As New MailMessage(fromName, toName)
With mailObj
.Body = body.ToString
.Priority = MailPriority.High
.Subject = "Test"
.IsBodyHtml = True
.Attachments.Add(New Attachment(attachment1Name))
.Attachments.Add(New Attachment(attachment2Name))

End With

Dim mailserver As New SmtpClient(server)
mailserver.Send(mailObj)

File.Delete(attachment1Name)
File.Delete(attachment2Name)




- Brad


 
Reply With Quote
 
 
 
 
MSDN
Guest
Posts: n/a
 
      04-25-2006
mailObj.Dispose() Releases it.

SA


"Brad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a web .Net app which sends emails with attachments. After the email
> is sent I clean up aftermyself and delete the attachments from disk. In
> upgrading to .Net 2 I changed the email logic from using system.web.mail
> to
> system.net.mail (of course vs is telling me system.web.mail is obsolete).
> In .Net 1.1, the files deleted with no problem but in .Net 2 when I
> attempt
> to delete I receive
>
> The process cannot access the file ...' because it is being used by
> another
> process.
>
> If I change the code back to using system.web.mail I can delete the files.
> So it would appear that something about the mail object, using
> system.net.mail, keeps the file in use. I found the same is true if I
> attempt to overwrite the files using something like File.Copy(from,to,
> true). Why in .Net 2 would the disk files still be in use...or at least
> how can they be released?
>
> Below is snip of code, both the 1.1 and 2.0 version.
>
> .Net 1.1 code
> ============================
> Dim mailObj As New System.Web.Mail.MailMessage()
> With mailObj
> .From = fromName
> .To = toName
> .Body = body.ToString
> .Priority = MailPriority.High
> .Subject = "Test"
> .BodyFormat = Mail.MailFormat.Html
> .Attachments.Add(New
> System.Web.Mail.MailAttachment(attachment1Name))
> .Attachments.Add(New
> System.Web.Mail.MailAttachment(attachment2Name))
>
> End With
>
> System.Web.Mail.SmtpMail.SmtpServer = server
> System.Web.Mail.SmtpMail.Send(mailObj)
>
> File.Delete(attachment1Name)
> File.Delete(attachment2Name)
> ========================================
>
>
> .Net 2.0 code
> ========================================
> Dim mailObj As New MailMessage(fromName, toName)
> With mailObj
> .Body = body.ToString
> .Priority = MailPriority.High
> .Subject = "Test"
> .IsBodyHtml = True
> .Attachments.Add(New Attachment(attachment1Name))
> .Attachments.Add(New Attachment(attachment2Name))
>
> End With
>
> Dim mailserver As New SmtpClient(server)
> mailserver.Send(mailObj)
>
> File.Delete(attachment1Name)
> File.Delete(attachment2Name)
>
>
>
>
> - Brad
>
>



 
Reply With Quote
 
 
 
 
Brad
Guest
Posts: n/a
 
      04-25-2006
It most certainly does, thank you very much.


"MSDN" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
mailObj.Dispose() Releases it.

SA


"Brad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a web .Net app which sends emails with attachments. After the email
> is sent I clean up aftermyself and delete the attachments from disk. In
> upgrading to .Net 2 I changed the email logic from using system.web.mail
> to
> system.net.mail (of course vs is telling me system.web.mail is obsolete).
> In .Net 1.1, the files deleted with no problem but in .Net 2 when I
> attempt
> to delete I receive
>
> The process cannot access the file ...' because it is being used by
> another
> process.
>
> If I change the code back to using system.web.mail I can delete the files.
> So it would appear that something about the mail object, using
> system.net.mail, keeps the file in use. I found the same is true if I
> attempt to overwrite the files using something like File.Copy(from,to,
> true). Why in .Net 2 would the disk files still be in use...or at least
> how can they be released?
>
> Below is snip of code, both the 1.1 and 2.0 version.
>
> .Net 1.1 code
> ============================
> Dim mailObj As New System.Web.Mail.MailMessage()
> With mailObj
> .From = fromName
> .To = toName
> .Body = body.ToString
> .Priority = MailPriority.High
> .Subject = "Test"
> .BodyFormat = Mail.MailFormat.Html
> .Attachments.Add(New
> System.Web.Mail.MailAttachment(attachment1Name))
> .Attachments.Add(New
> System.Web.Mail.MailAttachment(attachment2Name))
>
> End With
>
> System.Web.Mail.SmtpMail.SmtpServer = server
> System.Web.Mail.SmtpMail.Send(mailObj)
>
> File.Delete(attachment1Name)
> File.Delete(attachment2Name)
> ========================================
>
>
> .Net 2.0 code
> ========================================
> Dim mailObj As New MailMessage(fromName, toName)
> With mailObj
> .Body = body.ToString
> .Priority = MailPriority.High
> .Subject = "Test"
> .IsBodyHtml = True
> .Attachments.Add(New Attachment(attachment1Name))
> .Attachments.Add(New Attachment(attachment2Name))
>
> End With
>
> Dim mailserver As New SmtpClient(server)
> mailserver.Send(mailObj)
>
> File.Delete(attachment1Name)
> File.Delete(attachment2Name)
>
>
>
>
> - Brad
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 04-15-2011 04:00 AM
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 01-06-2011 05:00 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
attachments unable to read attachments from email bub.mk Computer Support 1 09-29-2004 02:29 AM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments