S
Seguros Catatumbo
Hi guys, i am having trouble deleting a file after sending an email.
The file is in use.
Here's the code:
String texto = "Test";
System.Net.Mail.SmtpClient smtp = new
System.Net.Mail.SmtpClient();
System.Net.Mail.MailMessage correo = new
System.Net.Mail.MailMessage();
correo.To.Add("(e-mail address removed)");
correo.Body = texto;
correo.IsBodyHtml = false;
string pdf="file.pdf";
correo.Attachments.Add(new
System.Net.Mail.Attachment(Server.MapPath(pdf)));
try
{
smtp.Send(correo);
}
catch (Exception)
{
}
finally{
File.Delete(pdf);
}
I have searched on the web and everyone seems to be doing it the same
way. I dont know if this is relevant, but i am creating that file from
itextsharp, a port of itext to c#, which reads a pdf form and saves it
to a new file, which is the one being attached. The pdf file (called a
"stamper") is being closed before the redirect to the email page
happens. And the email is sent succesfully with the attached file if i
don't delete it.
The file is in use.
Here's the code:
String texto = "Test";
System.Net.Mail.SmtpClient smtp = new
System.Net.Mail.SmtpClient();
System.Net.Mail.MailMessage correo = new
System.Net.Mail.MailMessage();
correo.To.Add("(e-mail address removed)");
correo.Body = texto;
correo.IsBodyHtml = false;
string pdf="file.pdf";
correo.Attachments.Add(new
System.Net.Mail.Attachment(Server.MapPath(pdf)));
try
{
smtp.Send(correo);
}
catch (Exception)
{
}
finally{
File.Delete(pdf);
}
I have searched on the web and everyone seems to be doing it the same
way. I dont know if this is relevant, but i am creating that file from
itextsharp, a port of itext to c#, which reads a pdf form and saves it
to a new file, which is the one being attached. The pdf file (called a
"stamper") is being closed before the redirect to the email page
happens. And the email is sent succesfully with the attached file if i
don't delete it.