Click here to Skip to main content
15,917,793 members
Home / Discussions / C#
   

C#

 
GeneralRe: Double vs Decimal Pin
PIEBALDconsult19-Feb-08 9:23
mvePIEBALDconsult19-Feb-08 9:23 
GeneralRe: Double vs Decimal Pin
Guffa19-Feb-08 9:26
Guffa19-Feb-08 9:26 
GeneralRe: Double vs Decimal Pin
DaveyM6919-Feb-08 9:38
professionalDaveyM6919-Feb-08 9:38 
GeneralRe: Double vs Decimal Pin
Vodstok19-Feb-08 12:22
Vodstok19-Feb-08 12:22 
QuestionHelp required please: Document Upload and Email Verification Pin
Freeweight19-Feb-08 7:14
Freeweight19-Feb-08 7:14 
GeneralRe: Help required please: Document Upload and Email Verification Pin
DaveyM6919-Feb-08 7:28
professionalDaveyM6919-Feb-08 7:28 
GeneralRe: Help required please: Document Upload and Email Verification Pin
Freeweight19-Feb-08 8:26
Freeweight19-Feb-08 8:26 
GeneralRe: Help required please: Document Upload and Email Verification Pin
Michael900019-Feb-08 8:52
Michael900019-Feb-08 8:52 
Robert

In the code below the send-mail is moved out of the loop.
now just create a try-catch for the moved part

Regards
Michael



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));

}

//...send mail moved out of the loop...

}
catch (Exception Ex)
{
Label1.Text += "There was an error sending your files ... " + Ex.Message;
lblStatus.Text += "Your email failed to send correctly ..." + Ex.Message;
}
}

// 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.";


}
#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
Freeweight20-Feb-08 5:18
Freeweight20-Feb-08 5:18 
QuestionUsing xmlserialization to create an xml document...have a question [modified] Pin
LongRange.Shooter19-Feb-08 6:57
LongRange.Shooter19-Feb-08 6:57 
GeneralRe: Using xmlserialization to create an xml document...have a question Pin
Le centriste19-Feb-08 9:08
Le centriste19-Feb-08 9:08 
GeneralRe: Using xmlserialization to create an xml document...have a question Pin
LongRange.Shooter20-Feb-08 7:14
LongRange.Shooter20-Feb-08 7:14 
GeneralMaking Install Pin
Matjaz-xyz19-Feb-08 6:53
Matjaz-xyz19-Feb-08 6:53 
GeneralRe: Making Install Pin
Judah Gabriel Himango19-Feb-08 7:43
sponsorJudah Gabriel Himango19-Feb-08 7:43 
QuestionBackgroundWorker doesn't trigger ProgressChanged event Pin
Jayman36919-Feb-08 6:52
Jayman36919-Feb-08 6:52 
GeneralRe: BackgroundWorker doesn't trigger ProgressChanged event Pin
DaveyM6919-Feb-08 7:32
professionalDaveyM6919-Feb-08 7:32 
QuestionRe: BackgroundWorker doesn't trigger ProgressChanged event Pin
Jayman36919-Feb-08 7:51
Jayman36919-Feb-08 7:51 
GeneralRe: BackgroundWorker doesn't trigger ProgressChanged event Pin
DaveyM6919-Feb-08 9:34
professionalDaveyM6919-Feb-08 9:34 
QuestionRe: BackgroundWorker doesn't trigger ProgressChanged event Pin
Jayman36919-Feb-08 9:46
Jayman36919-Feb-08 9:46 
GeneralRe: BackgroundWorker doesn't trigger ProgressChanged event Pin
DaveyM6919-Feb-08 10:09
professionalDaveyM6919-Feb-08 10:09 
GeneralRe: BackgroundWorker doesn't trigger ProgressChanged event Pin
Scott Dorman21-Feb-08 5:17
professionalScott Dorman21-Feb-08 5:17 
Generalmasked textbox cursor Pin
NewToAspDotNet19-Feb-08 5:59
NewToAspDotNet19-Feb-08 5:59 
GeneralRe: masked textbox cursor Pin
Skippums19-Feb-08 6:30
Skippums19-Feb-08 6:30 
QuestionItems in ListView changed [modified] Pin
C-Scharbe19-Feb-08 5:16
C-Scharbe19-Feb-08 5:16 
GeneralRe: Items in ListView changed Pin
LongRange.Shooter19-Feb-08 7:17
LongRange.Shooter19-Feb-08 7:17 

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.