Hey Guys, based on some sample code that was posted in the forum, if I try to attach the uploaded file(s) to an email message, the attachements appear as "persisted" files in the email. At what point should I attach it to the message because it appears I'm doing it too early. Please advise. Here is the sample source code im working with:
<%
@ Page Language="C#" Title="First sample" %>
<%
@ Import Namespace="CuteWebUI" %>
<%
@ Register Assembly="CuteWebUI.AjaxUploader" Namespace="CuteWebUI" TagPrefix="CuteWebUI" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<
script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
System.Net.Mail.
MailMessage msg = new System.Net.Mail.MailMessage();
msg.From =
new System.Net.Mail.MailAddress("[email protected]");
msg.To.Add(
"[email protected]");
msg.Subject =
"Test";
msg.Body =
"Test";
foreach (AttachmentItem item in UploadAttachments1.Items)
{
if (!item.Checked) continue;
//string filename = item.FileName;
//int filesize=item.FileSize;
//Stream stream = item.OpenStream();
System.Net.Mail.
Attachment ma = new System.Net.Mail.Attachment(item.GetTempFilePath());
msg.Attachments.Add(ma);
}
//System.Net.Mail.SmtpMail.Send(msg);
System.Net.Mail.
SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
smtpClient.Send(msg);
}
</
script>
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head id="Head1" runat="server">
</
head>
<
body>
<form id="Form1" runat="server">
<CuteWebUI:UploadAttachments ID="UploadAttachments1" runat="server" InsertText="UploadAttachments1">
</CuteWebUI:UploadAttachments>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send" Width="107px" />
</form>
</
body>
</
html>