Click here to Skip to main content
15,892,253 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need Help Understanding Error Handling Pin
JDM67636-Dec-10 10:09
JDM67636-Dec-10 10:09 
GeneralRe: Need Help Understanding Error Handling Pin
DaveyM698-Dec-10 2:48
professionalDaveyM698-Dec-10 2:48 
GeneralRe: Need Help Understanding Error Handling Pin
Luc Pattyn8-Dec-10 4:35
sitebuilderLuc Pattyn8-Dec-10 4:35 
AnswerRe: Need Help Understanding Error Handling Pin
PIEBALDconsult6-Dec-10 12:21
mvePIEBALDconsult6-Dec-10 12:21 
Questionhow to convert dataset to excell ? Pin
Gali19786-Dec-10 9:04
Gali19786-Dec-10 9:04 
AnswerRe: how to convert dataset to excell ? Pin
Pawel Gielmuda6-Dec-10 22:50
Pawel Gielmuda6-Dec-10 22:50 
AnswerRe: how to convert dataset to excell ? Pin
RaviRanjanKr17-Dec-10 18:02
professionalRaviRanjanKr17-Dec-10 18:02 
QuestionSending attachments with SMTP Client Pin
musefan6-Dec-10 3:39
musefan6-Dec-10 3:39 
Hi All,

My requirement is... Generate a file, send that file as attachment using SMTP client and then delete the generated file.

I have generated the file fine.
I have implemented SMTP client usage fine.

first attempt error - file in use when trying to delete after sending email...

message.Attachments.Add(new System.Net.Mail.Attachment("FILEPATH"));
smtp.Send(message);


...OK, so SEND is for some reason still using the file. I have just removed another load of almost posted text as I have figured out the answer. Which is basically...

Collection<Stream> streams = new Collection<Stream>();

foreach(string filename in filenames)
{
   System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
   Stream stream = new MemoryStream(File.ReadAllBytes(filename));
   message.Attachments.Add(new System.Net.Mail.Attachment(stream, fileInfo.Name, null));
   streams.Add(stream);
}

smtp.Send(message);

foreach(Stream stream in streams)
   stream.Close();


So I have solved my problem, but have still posted as may be useful for others but also, does anybody know why adding an attachment via a file path keeps the file locked after sending?
Life goes very fast. Tomorrow, today is already yesterday.

AnswerRe: Sending attachments with SMTP Client Pin
OriginalGriff6-Dec-10 3:42
mveOriginalGriff6-Dec-10 3:42 
GeneralRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 3:52
musefan6-Dec-10 3:52 
AnswerRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 4:15
musefan6-Dec-10 4:15 
AnswerRe: Sending attachments with SMTP Client [modified] Pin
PIEBALDconsult6-Dec-10 4:16
mvePIEBALDconsult6-Dec-10 4:16 
GeneralRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 4:20
musefan6-Dec-10 4:20 
GeneralRe: Sending attachments with SMTP Client Pin
PIEBALDconsult6-Dec-10 4:24
mvePIEBALDconsult6-Dec-10 4:24 
GeneralRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 4:30
musefan6-Dec-10 4:30 
GeneralRe: Sending attachments with SMTP Client Pin
PIEBALDconsult6-Dec-10 4:40
mvePIEBALDconsult6-Dec-10 4:40 
GeneralRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 4:57
musefan6-Dec-10 4:57 
GeneralRe: Sending attachments with SMTP Client Pin
PIEBALDconsult6-Dec-10 5:32
mvePIEBALDconsult6-Dec-10 5:32 
GeneralRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 5:46
musefan6-Dec-10 5:46 
GeneralRe: Sending attachments with SMTP Client Pin
PIEBALDconsult6-Dec-10 5:57
mvePIEBALDconsult6-Dec-10 5:57 
GeneralRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 6:08
musefan6-Dec-10 6:08 
GeneralRe: Sending attachments with SMTP Client Pin
PIEBALDconsult6-Dec-10 6:22
mvePIEBALDconsult6-Dec-10 6:22 
GeneralRe: Sending attachments with SMTP Client Pin
musefan6-Dec-10 6:39
musefan6-Dec-10 6:39 
GeneralRe: Sending attachments with SMTP Client Pin
PIEBALDconsult6-Dec-10 7:21
mvePIEBALDconsult6-Dec-10 7:21 
AnswerRe: Sending attachments with SMTP Client Pin
Luc Pattyn6-Dec-10 4:16
sitebuilderLuc Pattyn6-Dec-10 4:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.