Hi,
I have created a Contact form for my website. The design is as follows.
Name -
Subject -
Email -
Phone -
Resusme -(File Upload Control)
Send Button.
This layout of my contact form..
aspx coding as follows.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 43%;
height: 182px;
}
.style2
{
width: 83px;
font-family: "Agency FB";
font-weight: bold;
}
.style3
{
width: 83px;
font-family: Verdana;
font-weight: bold;
}
.style4
{
width: 437px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table border="2" class="style1">
<tr>
<td class="style3">
Name</td>
<td class="style4">
<asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
Suject</td>
<td class="style4">
<asp:TextBox ID="SubjectTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
Email</td>
<td class="style4">
<asp:TextBox ID="EmailTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
Phone</td>
<td class="style4">
<asp:TextBox ID="PhoneTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
Resume.</td>
<td class="style4">
<asp:FileUpload ID="ResumeFileUpload" runat="server" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style4">
<asp:Button ID="SendButton" runat="server" Text="Send"
onclick="Button1_Click" />
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>
and aspx.cs coding is as follows
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/Contact.txt");
string mailBody = System.IO.File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", NameTextBox.Text);
mailBody = mailBody.Replace("##Subject##", SubjectTextBox.Text);
mailBody = mailBody.Replace("##Email##", EmailTextBox.Text);
mailBody = mailBody.Replace("##Phone##", PhoneTextBox.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("
[email protected]", "Abhishek Kumar");
myMessage.To.Add(new MailAddress("
[email protected]", "Contact Soon"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
}
}
}
}
Contact.txt Coding as follows...
Hi Admin,
A visitor has left the following feedback at the site:
Name :##Name##
Subject :##Subject##
Email :##Email##
Phone :##Phone##
My contact form is working fine the content of textbox is getting delivered on my email id but the only problem is that I want that the email delivred with attachment of file upload control whcih is I am unable to undestand how to do. that is why I have not made any progarmming for that. Pls help what should be coding for file upload control so that the content of file upload getting delivered with text box content as attachment. Pls help me.