But when we upload the site on webserver, and run the application the attachment was not uploaded because the attach file is not finding on web server.
Our code is
Expand|Select|Wrap|Line Numbers
- using System;
- 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;
- using System.IO;
- public partial class _Default : System.Web.UI.Page
- {
- String filename;
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void zSubmitBt_Click(object sender, EventArgs e)
- {
- try
- {
- MailMessage mail = new MailMessage();
- mail.To.Add ("tomailaddress.com");
- mail.From = new MailAddress("frommailaddress.com");
- mail.Subject = "Resume";
- string ml;
- if (zMaleRBt.Checked)
- ml = zMaleRBt.Text;
- else
- ml = zFemaleRBt.Text;
- //--------------------
- string matter = "<u><strong> Personal Detail :: </strong></u><br/> " +
- "<br/> User Name______________ : " + zTbFName.Text + " " + zTbLName.Text +
- "<br/> Mobile Number___________ : " + zTbMobNo.Text +
- "<br/> Email___________________ : " + zEmailTb.Text +
- "<br/> DOB (dd/mm/yy)__________: " + zAgeDayDDL.Text + "/" + zAgeMonthDDL.Text + "/" + zAgeYearDDL.Text +
- "<br/> Gender__________________ : " + ml +
- // "<br/> Gender__________________ : "+ zMaleRBt.Text+ "/" + zFemaleRBt.Text +
- "<br/> Contact Address__________ : " + zAddressTb.Text +
- "<br/> Native City Name__________ : " + zCityNameTb.Text +
- "<br/><hr><br/><u><strong>Professional Detail ::</strong></u><br/>" +
- "<br/> Total Experience(yy/mm)__ : " + zTotalEYDDL.Text + "/" + zTotalEMDDL.Text +
- "<br/> Job Category____________ : " + zJobCatListDDL.Text +
- "<br/> Key Skill_______________ : " + zKeySkillTb.Text +
- "<br/> Current Employer________ : " + zCurrentCNameTb.Text +
- "<br/> Current Salary (p.a.)______ : " + zCSalaryTb.Text +
- "<br/> Expected Salary (p.a.)____ : " + zESalaryTb.Text +
- "<br/><hr><br/><u><strong>Educationl Qualification ::</strong></u><br/>" +
- "<br/> Highest Qualification___ : " + zHQualificationDDL.Text +
- "<br/> Specialization_________ : " + zSpecializationDDL.Text +
- "<br/> University/College______ : " + zCollegeDDL.Text +
- "<br/> Other College_________ : " + zCollegeNotATb.Text +
- "<br/> User Resume_________ : ";
- mail.Body = matter;
- mail.IsBodyHtml = true;
- // ----------------
- string strFileName = Path.GetFileName(zUpload.PostedFile.FileName);
- zUpload.PostedFile.SaveAs(Server.MapPath("~\\") + strFileName);
- System.Net.Mail.Attachment data1 = new System.Net.Mail.Attachment(Server.MapPath(strFileName));
- mail.Attachments.Add(data1);
- mail.Priority = MailPriority.High;
- SmtpClient smtp = new SmtpClient();
- //smtp.Port = 587;
- smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
- smtp.Credentials = new System.Net.NetworkCredential("frommailaddress.com", "password");
- //Or your Smtp Email ID and Password
- smtp.EnableSsl = true;
- smtp.Send(mail);
- zSubmitResp.Visible = true;
- zSubmitResp.Text = "Record Successfully Submitted";
- //zSubmitResp.Text = strFileName;
- //--------
- zTbFName.Text = "";
- zTbLName.Text = "";
- zTbMobNo.Text = "";
- zESalaryTb.Text = "";
- zEmailTb.Text = "";
- zCurrentCNameTb.Text = "";
- zCSalaryTb.Text = "";
- zCityNameTb.Text = "";
- zAddressTb.Text = "";
- zCollegeNotATb.Text = "";
- }
- catch (Exception ec)
- {
- zSubmitResp.Visible = true;
- zSubmitResp.Text = ec.ToString();
- }
- }
- }