Click here to Skip to main content
15,914,419 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Confirm box's title Pin
keyboard warrior14-Feb-08 7:23
keyboard warrior14-Feb-08 7:23 
GeneralRe: Confirm box's title Pin
Johnny ²13-Feb-08 17:21
Johnny ²13-Feb-08 17:21 
GeneralRe: Confirm box's title Pin
Shog914-Feb-08 4:02
sitebuilderShog914-Feb-08 4:02 
QuestionCalling/firing/triggering an event from a button click Pin
Brendan Vogt13-Feb-08 0:46
Brendan Vogt13-Feb-08 0:46 
GeneralRe: Calling/firing/triggering an event from a button click Pin
Paddy Boyd13-Feb-08 5:01
Paddy Boyd13-Feb-08 5:01 
Questiononbeforeunload firing twice Pin
Brendan Vogt12-Feb-08 23:24
Brendan Vogt12-Feb-08 23:24 
GeneralRe: onbeforeunload firing twice Pin
Ioan Anton14-Feb-08 10:33
Ioan Anton14-Feb-08 10:33 
QuestionHelp required please: Document Upload and Email Verification Pin
Freeweight12-Feb-08 6:14
Freeweight12-Feb-08 6:14 
Hi All

I am trying to allow one to three (3) files to be uploaded to a server, then send an email to the recipient for verification.

The files upload correctly and the email is sent, however it sends three emails for the one upload process.

What do I need to change in the code so that I only send one email for the complete process?

Any help would be appreciated.

Regards
Robert Caya


Here is the code for the process ...


default.aspx

]]>





<title>Document Upload and Email Verification



Document Upload and Email Form Sender








<asp:fileupload id="FileUpload1" cssclass="textSmall" runat="server" width="250px">


<asp:fileupload id="FileUpload2" cssclass="textSmall" runat="server" width="250px">


<asp:fileupload id="FileUpload3" cssclass="textSmall" runat="server" width="250px">



 Your Name: <asp:textbox id="txtName" cssclass="textSmall" width="241" runat="server">
 Your Email Address: <asp:textbox id="txtEmail" cssclass="textSmall" width="241" runat="server">
 Your Comments:
<asp:textbox id="txtMessage" width="100%" runat="server" height="99" textmode="MultiLine" maxlength="400">
 
 
<asp:button id="Button1" cssclass="textSmall" runat="server" text="Send Now" onclick="Button1_Click">
 
<asp:button id="Button2" cssclass="textSmall" runat="server" text="Reset" onclick="Button2_Click">
 
<asp:label id="lblStatus" runat="server" enableviewstate="False">
 

<asp:label id="Label1" cssclass="textSmall" runat="server">  






<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server">
ErrorMessage="You must enter your name." ControlToValidate="txtName">


<asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server">
ControlToValidate="txtEmail" ErrorMessage="You must enter your email address">




<asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server">
ControlToValidate="txtEmail" ErrorMessage="Please correct the format of your email to: example "someone@somewhere.com"."
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">






default.aspx.cs

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class _mailUpload : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)

{
string filepath = "d:\\Uploads";
HttpFileCollection uploadedFiles = Request.Files;
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);

for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];

try
{
if (userPostedFile.ContentLength > 0)
{
Label1.Text += "File #" + (i + 1) + "
";
Label1.Text += "File Name: " + userPostedFile.FileName + "
";
Label1.Text += "File Size: " + userPostedFile.ContentLength + "kb

";

userPostedFile.SaveAs(filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName));

}

// Default is localhost or you can specify a host name or ipaddress of the email server
smtpClient.Host = "localhost";

//Default port is 25
smtpClient.Port = 25;

//From address will be given as a MailAddress Object
message.From = fromAddress;

// To address collection of MailAddress
message.To.Add("rob@mydomain.com");
message.Subject = "Client File Upload System";

// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1@yoursite.com")
//message.CC.Add("admin1@yoursite.com");
//message.CC.Add("admin2@yoursite.com");

// You can specify Address directly as string
//message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
//message.Bcc.Add(new MailAddress("admin4@yoursite.com"));

//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = true;

// Message body content
message.Body = txtMessage.Text + "

The following files have been uploaded to the server.

" + Label1.Text;

// Send SMTP mail
smtpClient.Send(message);

lblStatus.Text = "Your email has been successfully sent.

The following files have been uploaded to the server.";
}
catch (Exception Ex)
{
Label1.Text += "There was an error sending your files ...
" + Ex.Message;
lblStatus.Text += "Your email failed to send correctly ...
" + Ex.Message;
}
}
}
#region "Reset"
protected void Button2_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtEmail.Text = "";
txtMessage.Text = "";
Label1.Text = "";
}
#endregion


}


GeneralRe: Help required please: Document Upload and Email Verification Pin
Steve Westbrook12-Feb-08 9:53
Steve Westbrook12-Feb-08 9:53 
Generalgenerating reports and exporting to .xls, .pdf and word Pin
livez12-Feb-08 4:24
livez12-Feb-08 4:24 
GeneralRe: generating reports and exporting to .xls, .pdf and word Pin
Paddy Boyd12-Feb-08 4:31
Paddy Boyd12-Feb-08 4:31 
GeneralRe: generating reports and exporting to .xls, .pdf and word Pin
livez12-Feb-08 20:15
livez12-Feb-08 20:15 
GeneralCannot use a leading .. to exit above the top directory. Pin
acodman12-Feb-08 3:29
acodman12-Feb-08 3:29 
GeneralRe: Cannot use a leading .. to exit above the top directory. Pin
andyharman12-Feb-08 7:47
professionalandyharman12-Feb-08 7:47 
GeneralRe: Cannot use a leading .. to exit above the top directory. Pin
Expert Coming13-Feb-08 4:56
Expert Coming13-Feb-08 4:56 
QuestionConfirming When Exiting Without Saving Pin
Brendan Vogt12-Feb-08 0:28
Brendan Vogt12-Feb-08 0:28 
GeneralRe: Confirming When Exiting Without Saving Pin
dfz12-Feb-08 2:03
dfz12-Feb-08 2:03 
QuestionRe: Confirming When Exiting Without Saving Pin
Brendan Vogt12-Feb-08 22:00
Brendan Vogt12-Feb-08 22:00 
GeneralRe: Confirming When Exiting Without Saving Pin
dfz13-Feb-08 2:51
dfz13-Feb-08 2:51 
GeneralWhats the difference javascript Pin
Cape Town Developer11-Feb-08 23:33
Cape Town Developer11-Feb-08 23:33 
GeneralRe: Whats the difference javascript Pin
Christian Graus11-Feb-08 23:42
protectorChristian Graus11-Feb-08 23:42 
GeneralRe: Whats the difference javascript Pin
Cape Town Developer11-Feb-08 23:43
Cape Town Developer11-Feb-08 23:43 
GeneralRe: Whats the difference javascript Pin
Cape Town Developer11-Feb-08 23:43
Cape Town Developer11-Feb-08 23:43 
AnswerRe: Whats the difference javascript Pin
Guffa12-Feb-08 11:52
Guffa12-Feb-08 11:52 
Generalinput type ="file" control for file uploading. Pin
ritu432111-Feb-08 23:03
ritu432111-Feb-08 23:03 

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.