Author: Robert Barnes | Posted on: 7/26/2009 6:58:40 PM | Views : 985

This is a part of my previous problem, http://forums.asp.net/p/1450851/3310560.aspx#3310560  (Create an email attachment: File in use error).
I found an article by Wayne Berry that seemed to perfectly address my problem: -

http://www.15seconds.com/Issue/060803.htm
The basic concept is to use create a memorystream as the attachment is generated, and then attach this to the email.  This avoids the need to create a file with the attendent file-in-use problems, potential threading issues, and of course the clean-up issues. But I found that Berry's code didn't seem to work: -
He wrote
       using System.net.mail

       MemoryStream memorystream = new FileStream();
       StreamWriter streamwriter = new StreamWriter(file);
       streamwr ...

Go to the complete details ...