ButterflyEffect
Power Member
boa tarde. precisava de fazer algo dest genero e encontrei o codigo e adaptei-o mas da-me este erro.podiam ajudarm?
cumps
erro
F:\liz.txtNumber of attachments are1Ocorreu uma falha na ligação do transporte ao servidor.
codigo
cumps
erro
F:\liz.txtNumber of attachments are1Ocorreu uma falha na ligação do transporte ao servidor.
codigo
Código:
protected void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
// button used to send the email
protected void Button1_Click(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To = txtTo.Text;
mail.From = txtFrom.Text;
mail.Subject = txtSubject.Text;
mail.Body = txtBody.Text;
MailAttachment attachment = null;
try
{
// check to see if there are any attachments or not
if(FileList.Items.Count > 0)
{
foreach(ListItem l in FileList.Items)
{
// Attaches a new attachment contained in the List
Response.Write(l.Text);
attachment = new MailAttachment(l.Text);
mail.Attachments.Add(attachment);
}
}
//mail.Attachments.Add(attachment);
Response.Write("Number of attachments are"+mail.Attachments.Count);
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
}
catch(Exception ex)
{
Response.Write(ex.Message);
// Cacthes the exception here
}
}
// Button used to attach a file
protected void Button2_Click(object sender, System.EventArgs e)
{
// gets the file name with the whole path
string attachedFile = File1.PostedFile.FileName;
// Adds the item in the list of attached files
if(attachedFile != "")
{
FileList.Items.Add(attachedFile);
}
}
}
}
Última edição pelo moderador: