Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2011, 07:30 AM
Authorized User
 
Join Date: Feb 2011
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to create contact form with file upload control ?

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Contact Form Control Problems with jQuery b_clodius BOOK: Beginning ASP.NET 4 : in C# and VB 9 May 23rd, 2010 12:36 PM
Clear the filepath details of File Upload Control after saving a file DineshGirij008 C# 2005 0 March 7th, 2009 03:52 AM
Chapter 9 pps 314-316 Contact Form User Control Featheriver BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 February 2nd, 2009 03:19 AM
Create/Upload a file on a Remote Machine SmboInc C# 2 November 20th, 2006 12:42 PM
how to create upload file image kuongnp ASP.NET 1.0 and 1.1 Basics 2 April 2nd, 2006 08:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.