我想用asp.net上传文件 [英] i want to upload file using asp.net
问题描述
<%@ Page Language="C#" MasterPageFile="~/phoenix.master" AutoEventWireup="true" CodeFile="RegisterationForm.aspx.cs" Inherits="RegisterationForm" Title="Phoenix Technology" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style2
{
width: 497px;
margin-left: 200px;
}
.style3
{
height: 2px;
width: 42%;
}
.style4
{
width: 497px;
margin-left: 200px;
height: 2px;
}
.style8
{
width: 497px;
margin-left: 200px;
height: 31px;
}
.style5
{
height: 16px;
width: 42%;
}
.style6
{
width: 497px;
margin-left: 200px;
height: 16px;
}
.style1
{
height: 58px;
}
.style9
{
width: 42%;
}
.style10
{
width: 42%;
height: 41px;
}
.style11
{
width: 497px;
margin-left: 200px;
height: 41px;
}
.banner_img
{
height: 946px;
}
.style12
{
width: 42%;
height: 51px;
}
.style13
{
width: 497px;
margin-left: 200px;
height: 51px;
}
.style14
{
width: 42%;
height: 66px;
}
.style15
{
width: 497px;
margin-left: 200px;
height: 66px;
}
</style>
<asp:Content ID="Content2" runat="server"
contentplaceholderid="ContentPlaceHolder4">
<div id="body" style="height: 1117px">
<script language="javascript" >
function validate() {
var name = document.getElementById("<%=txt_name.ClientID %>")
var email = document.getElementById("<%=txt_email.ClientID%>")
var country = document.getElementById("<%=txt_country.ClientID%>")
var address = document.getElementById("<%=txt_address.ClientID%>")
var state = document.getElementById("<%=txt_state.ClientID%>")
var city = document.getElementById("<%=txt_city.ClientID%>")
var area = document.getElementById("<%=DropDownList1.ClientID%>")
var yearofexperience = document.getElementById("<%=txt_yoe.ClientID%>")
var mobile = document.getElementById("<%=txt_mobile.ClientID%>")
var upload = document.getElementById("<%=uploadResume.ClientID%>")
if (name.value == "") {
alert("Name cannot be blank");
name.focus();
return false;
}
if (email.value == "") {
alert("Email id cannot be blank");
email.focus();
return false;
}
if (area.value == "") {
alert("should be mandatory");
area.focus();
return false;
}
if (yearofexperience.value == "") {
alert("should be mandatory");
yearofexperience.focus();
return false;
}
if (mobile.value == "") {
alert("should not be null");
mobile.focus();
return false;
}
// if (mobile.value == String) {
// alert("Enter only number");
// mobile.focus();
// return false;
// }
// if (mobile.nodeValue<10)
// {
// alert("Enter only 10 digit number");
// mobile.focus();
// return false;
//
// }
if (city.value == "") {
alert("should be mandatory");
city.focus();
return false;
}
if (state.value == "") {
alert("should be mandatory");
state.focus();
return false;
}
if (country.value == "") {
alert("should be mandatory");
country.focus();
return false;
}
if (address.value == "") {
alert("should be mandatory");
address.focus();
return false;
}
if(upload.value="No file selected.")
{
alert("upload the resume");
upload.focus();
return false;
}
var emailPat = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var emailid = email.value;
var matchArray = emailid.match(emailPat);
if (matchArray == null) {
alert("Your email address seems incorrect. Please try again.");
email.focus();
return false;
}
// if (addinfo.value == "") {
// alert("Additional Information cannot be blank");
// addinfo.focus();
// return false;
// }
}
function resume_onclick() {
}
function upload_onclick() {
}
</script>
<div class="updown">
<div class="banner_menu">
<div class="both">
</div>
</div>
</div>
<div class="banner_slide">
<div class="banner_img">
<asp:Label ID="lbl_date" runat="server">
<br />
<br />
<table align="center" cellpadding="5">
style="width: 812px; margin-removed 0px">
<tr>
<asp:Label ID="Label1" runat="server" Text="Registration "
Font-Bold="True" Font-Size="XX-Large" ForeColor="Black"
Font-Names="raavi">
<asp:Label ID="Label2" runat="server" Text="Form"
Font-Size="XX-Large" Font-Bold="True" ForeColor="#C60000"
Font-Names="raavi">
</tr>
<tr>
<td class="style10">
style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
Name</td>
<td class="style11">
<asp:TextBox ID="txt_name" runat="server" Width="184px">
</td>
</tr>
<tr>
<td class="style12">
style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F"
align="justify">
Qualification</td>
<td class="style13">
<asp:DropDownList ID="droplst_qulification" runat="server" AutoPostBack="False"
Height="30px" Width="182px">
<asp:ListItem>
<asp:ListItem>B.E(Computer Science Engineering)
<asp:ListItem>B.E(Information Technology)
<asp:ListItem>B.E(Electronics and Communication)
<asp:ListItem>B.E(Electricals and Electronics)
<asp:ListItem>B.E(Mechanical Engineering)
<asp:ListItem>MBA
<asp:ListItem>MCA
<asp:ListItem>B.Sc
<asp:ListItem>M.Sc
<asp:ListItem>BBA
<asp:ListItem>Diploma
<asp:ListItem>Others..
<asp:ListItem>
</td>
</tr>
<tr>
<td class="style14">
style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F"
align="justify">
Area of Interest
<td class="style15">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="False"
Height="30px" Width="171px">
<asp:ListItem>
<asp:ListItem>C
<asp:ListItem>C++
<asp:ListItem>JAVA
<asp:ListItem>.NET
<asp:ListItem>PHP
<asp:ListItem>VOICE
<asp:ListItem>NON-VOICE
<asp:ListItem>MAINFRAME
<asp:ListItem>Others...
</td>
</td></tr>
<tr>
<td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
Years of Experience </td>
<td class="style2">
<asp:TextBox ID="txt_yoe" runat="server" MaxLength="2" Width="24px">
</td>
</tr>
<tr>
<td class="style3" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
Mobile</td>
<td class="style4">
<asp:TextBox ID="txt_mbno" runat="server" Height="23px" MaxLength="3"
ReadOnly="True" style="margin-top: 0px" Width="56px">+91
<asp:TextBox ID="txt_mobile" runat="server" MaxLength="10" Width="117px" >
</td>
</tr>
<tr>
<td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
E-mail ID</td>
<td class="style8">
<asp:TextBox ID="txt_email" runat="server" Width="184px">
</td>
</tr>
<tr>
<td class="style5" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
Address</td>
<td class="style6">
<asp:TextBox ID="txt_address" runat="server" Height="90px" TextMode="MultiLine"
Width="184px">
</td>
</tr>
<tr>
<td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
Country</td>
<td class="style2">
<asp:TextBox ID="txt_country" runat="server" Width="184px">
</td>
</tr>
<tr>
<td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
City</td>
<td class="style2">
<asp:TextBox ID="txt_city" runat="server" Width="184px">
</td>
</tr>
<tr>
<td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
State</td>
<td class="style2">
<asp:TextBox ID="txt_state" runat="server" Width="184px">
</td>
</tr>
<tr>
<td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify">
Upload Resume</td>
<td class="style2">
<asp:FileUpload ID="uploadResume" runat="server" Height="29px"
Width="218px" />
<td>
</td>
</td></tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td align="center" class="style1" colspan="2">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
OnClientClick="return validate();" Text="Submit" Height="36px" />
<br />
<br />
</td>
</tr>
</table>
</div>
</div>
</div>
my C# code is
my C# code is
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.Xml;
using System.IO;
public partial class RegisterationForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lbl_date.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
lbl_date.Text = DateTime.Today.ToShortDateString();
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("formxml.xml"));
XmlElement parentelement = xmldoc.CreateElement("registeration");
XmlElement Date = xmldoc.CreateElement("Date");
Date.InnerText = lbl_date.Text;
XmlElement Name = xmldoc.CreateElement("Name");
Name.InnerText = txt_name.Text;
XmlElement Qualification = xmldoc.CreateElement("Qualification");
Qualification.InnerText = droplst_qulification.Text;
XmlElement areaofinterest = xmldoc.CreateElement("areaofinterest");
areaofinterest.InnerText = DropDownList1.Text;
XmlElement yearofexperience = xmldoc.CreateElement("yearofexperience");
yearofexperience.InnerText = txt_yoe.Text;
XmlElement Mobile = xmldoc.CreateElement("Mobile");
Mobile.InnerText = txt_mobile.Text;
XmlElement EmailID = xmldoc.CreateElement("EmailID");
EmailID.InnerText = txt_email.Text;
XmlElement Address = xmldoc.CreateElement("Address");
Address.InnerText = txt_address.Text;
XmlElement Country = xmldoc.CreateElement("Country");
Country.InnerText = txt_country.Text;
XmlElement City = xmldoc.CreateElement("City");
City.InnerText = txt_city.Text;
XmlElement state = xmldoc.CreateElement("state");
state.InnerText = txt_state.Text;
string pathname ="C:\\Documents and Settings\\Sweet Pc\\Desktop\\WebSite12\\uploadResume\\";
string filename = uploadResume.FileName;
string fullpath = pathname + filename;
XmlElement Resume = xmldoc.CreateElement("Resume");
Resume.InnerText = fullpath;
parentelement.AppendChild(Date);
parentelement.AppendChild(Name);
parentelement.AppendChild(Qualification);
parentelement.AppendChild(areaofinterest);
parentelement.AppendChild(yearofexperience);
parentelement.AppendChild(Mobile);
parentelement.AppendChild(EmailID);
parentelement.AppendChild(Address);
parentelement.AppendChild(Country);
parentelement.AppendChild(City);
parentelement.AppendChild(state);
parentelement.AppendChild(Resume);
xmldoc.DocumentElement.AppendChild(parentelement);
xmldoc.Save(Server.MapPath("formxml.xml"));
uploadResume.SaveAs(Server.MapPath("uploadResume\\" + uploadResume.FileName));
txt_name.Text = "";
droplst_qulification.Text = "";
DropDownList1.Text = "";
txt_yoe.Text = "";
txt_mobile.Text = "";
txt_email.Text = "";
txt_address.Text = "";
txt_country.Text = "";
txt_city.Text = "";
txt_state.Text = "";
}}
my xml file is
my xml file is
<registeration>
<date>
</date>
<name>
</name>
<qualification>
</qualification>
<areaofinterest>
</areaofinterest>
<yearofexperience>
</yearofexperience>
<mobile>
</mobile>
<emailid>
</emailid>
<address>
</address>
<country>
</country>
<city>
</city>
<state>
</state>
<resume>
</resume>
<registeration>
<date>8/1/2013</date>
<name>Rajesh</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C</areaofinterest>
<yearofexperience>7</yearofexperience>
<mobile>576</mobile>
<emailid>hsdof</emailid>
<address>sflvjl</address>
<country>sjf</country>
<city>jflsvg</city>
<state>jdpsvj</state>
<resume> C:\Documents and Settings\Administrator\Desktop\older\phoenix\uploadresume\Rajesh Resume (2).doc</resume>
</registeration>
<registeration>
<date>8/1/2013</date>
<name>rt</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C++</areaofinterest>
<yearofexperience>t</yearofexperience>
<mobile>tryr</mobile>
<emailid>fghf</emailid>
<address>gfh</address>
<country>fgh</country>
<city>fghmk</city>
<state>gfh</state>
<resume> C:\Documents and Settings\Administrator\Desktop\older\phoenix\uploadresumeRajesh Resume (2).doc</resume>
</registeration>
<registeration>
<date>8/1/2013</date>
<name>post</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C++</areaofinterest>
<yearofexperience>7</yearofexperience>
<mobile>8888888888</mobile>
<emailid>8</emailid>
<address>88</address>
<country>nhu</country>
<city>hu</city>
<state>hu</state>
<resume>C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\Rajesh Resume (2).doc</resume>
</registeration>
<registeration>
<date>8/7/2013</date>
<name>ram</name>
<qualification>B.E(Electronics and Communication)</qualification>
<areaofinterest>JAVA</areaofinterest>
<yearofexperience>2</yearofexperience>
<mobile>56786785</mobile>
<emailid>redfg</emailid>
<address>erg</address>
<country>efdgh</country>
<city>refgd</city>
<state>dfsg</state>
<resume>C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\SIVARAJ.doc</resume>
</registeration>
<registeration>
<date>8/7/2013</date>
<name>rewr</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C</areaofinterest>
<yearofexperience>4</yearofexperience>
<mobile>567457</mobile>
<emailid>rgfh</emailid>
<address>fgsnb</address>
<country>dgshn</country>
<city>dsgfh</city>
<state>dfsh</state>
<resume>C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\SIVARAJ.doc</resume>
</registeration>
</registeration>
i want to save the file in folder \"C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\"
pls suggest me
i want to save the file in folder "C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume"
pls suggest me
推荐答案
/;
var emailid = email.value;
var matchArray = emailid.match(emailPat);
if (matchArray == null) {
alert(\"Your email address seems incorrect. Please try again.\");
email.focus();
return false ;
}
// if (addinfo.value == \"\") {
// alert(\"Additional Information cannot be blank\");
// addinfo.focus();
// return false;
// }
}
function resume_onclick() {
}
function upload_onclick() {
}
</script>
<div class=\"updown\">
<div class=\"banner_menu\">
<div class=\"both\">
</div> ;
</div>
</div>
<div class=\"banner_slide\">
<div class=\"banner_img\">
<asp:Label ID=\"lbl_date\" runat=\"server\">
<br />
<br />
<table align=\"center\" cellpadding=\"5\">
style=\"width: 812px; margin-removed 0px\">
<tr>
<asp:Label ID=\"Label1\" runat=\"server\" Text=\"Registration \"
Font-Bold=\"True\" Font-Size=\"XX-Large\" ForeColor=\"Black\"
Font-Names=\"raavi\">
<asp:Label ID=\"Label2\" runat=\"server\" Text=\"Form\"
Font-Size=\"XX-Large\" Font-Bold=\"True\" ForeColor=\"#C60000\"
Font-Names=\"raavi\">
</tr>
<tr>
<td class=\"style10\">
style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
Name</td>
<td class=\"style11\">
<asp:TextBox ID=\"txt_name\" runat=\"server\" Width=\"184px\">
</td>
</tr>
<tr>
<td class=\"style12\">
style=\"font-family: 'r aavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\"
align=\"justify\">
Qualification</td>
<td class=\"style13\">
<asp:DropDownList ID=\"droplst_qulification\" runat=\"server\" AutoPostBack=\"False\"
Height=\"30px\" Width=\"182px\">
< asp:ListItem>
<asp:ListItem>B.E(Computer Science Engineering)
<asp:ListItem>B.E(Information Technology)
<asp:ListItem>B.E(Electronics and Communication)
<asp:ListItem>B.E(Electricals and Electronics)
<asp:ListItem>B.E(Mechanical Engineering)
<asp:ListItem>MBA
<asp:ListItem>MCA
<asp:ListItem>B.Sc
<asp:ListItem>M.Sc
<asp:ListItem>BBA
<asp:ListItem>Diploma
<asp:ListItem>Others..
<asp:ListItem>
</td>
</tr>
<tr>
<td class=\"style14\">
style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\"
align=\"justify\">
Area of Interest
<td class=\"style15\">
<asp:DropDownList ID=\"DropDownList1\" runat=\"server\" AutoPostBack=\"False\"
Height=\"30px\" Width=\"171px\">
<asp:ListItem>
<asp:ListItem>C
<asp:ListItem>C++
<asp:ListItem>JAVA
<asp:ListItem>.NET
<asp:ListItem>PHP
<asp:ListIt em>VOICE
<asp:ListItem>NON-VOICE
<asp:ListItem>MAINFRAME
<asp:ListItem>Others...
</td>
</td></tr>
<tr>
<td class=\"style9\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
Years of Experience </td>
<td class=\"style2\">
<asp:TextBox ID=\"txt_yoe\" runat=\"server\" MaxLength=\"2\" Width=\"24px\">
</td>
</tr>
<tr>
<td class=\"style3\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
Mobile</td>
<td class=\"style4\">
<asp:TextBox ID=\"txt_mbno\" runat=\"server\" Height=\"23px\" MaxLength=\"3\"
ReadOnly=\"True\" style=\"margin-top: 0px\" Width=\"56px\">+91
<asp:TextBox ID=\"txt_mobile\" runat=\"server\" MaxLength=\"10\" Width=\"117px\" >
</td>
</tr>
<tr>
<td class=\"style9\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
E-mail ID</td>
<td class=\"style8\">
<asp:TextBox ID=\" txt_email\" runat=\"server\" Width=\"184px\">
</td>
</tr>
<tr>
<td class=\"style5\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
Address</td>
<td class=\"style6\">
<asp:TextBox ID=\"txt_address\" runat=\"server\" Height=\"90px\" TextMode=\"MultiLine\"
Width=\" 184px\">
</td>
</tr>
<tr>
<td class=\"style9\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
Country</td>
<td class=\"style2\">
<asp:TextBox ID=\"txt_country\" runat=\"server\" Width=\"184px\">
</td>
</tr>
<tr>
<td class=\"style9\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
City</td>
<td class=\"style2\">
<asp:TextBox ID=\"txt_city\" runat=\"server\" Width=\"184px\">
</td>
</tr>
<tr>
<td class=\"style9\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
State</td>
<td class=\"style2\">
<asp:TextBox ID=\"txt_state\" runat=\"server\" Width=\"184px\">
</td>
</tr>
<tr>
<td class=\"style9\" style=\"font-family: 'raavi'; font-size:large; font-weight:normal; font-style:normal; font-variant: normal; text-transform:none; color: #5F5F5F\" align=\"justify\">
Upload Resume</td>
<td class=\"style2\">
<asp:FileUpload ID=\"uploadResume\" runat=\"server\" Height=\"29px\"
Width=\"218px\" />
$b$ b <td>
</td>
</td></tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td align=\"center\" class=\"style1\" colspan=\"2\">
<asp:Button ID=\"Button1\" runat=\"server\" onclick=\"Button1_Click\"
OnClientClick=\"return validate();\" Text=\"Submit\" Height=\"36px\" />
<br />
<br />
</td>
</tr>
</table>
</div>
</div>
</div>
/; var emailid = email.value; var matchArray = emailid.match(emailPat); if (matchArray == null) { alert("Your email address seems incorrect. Please try again."); email.focus(); return false; } // if (addinfo.value == "") { // alert("Additional Information cannot be blank"); // addinfo.focus(); // return false; // } } function resume_onclick() { } function upload_onclick() { } </script> <div class="updown"> <div class="banner_menu"> <div class="both"> </div> </div> </div> <div class="banner_slide"> <div class="banner_img"> <asp:Label ID="lbl_date" runat="server"> <br /> <br /> <table align="center" cellpadding="5"> style="width: 812px; margin-removed 0px"> <tr> <asp:Label ID="Label1" runat="server" Text="Registration " Font-Bold="True" Font-Size="XX-Large" ForeColor="Black" Font-Names="raavi"> <asp:Label ID="Label2" runat="server" Text="Form" Font-Size="XX-Large" Font-Bold="True" ForeColor="#C60000" Font-Names="raavi"> </tr> <tr> <td class="style10"> style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Name</td> <td class="style11"> <asp:TextBox ID="txt_name" runat="server" Width="184px"> </td> </tr> <tr> <td class="style12"> style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Qualification</td> <td class="style13"> <asp:DropDownList ID="droplst_qulification" runat="server" AutoPostBack="False" Height="30px" Width="182px"> <asp:ListItem> <asp:ListItem>B.E(Computer Science Engineering) <asp:ListItem>B.E(Information Technology) <asp:ListItem>B.E(Electronics and Communication) <asp:ListItem>B.E(Electricals and Electronics) <asp:ListItem>B.E(Mechanical Engineering) <asp:ListItem>MBA <asp:ListItem>MCA <asp:ListItem>B.Sc <asp:ListItem>M.Sc <asp:ListItem>BBA <asp:ListItem>Diploma <asp:ListItem>Others.. <asp:ListItem> </td> </tr> <tr> <td class="style14"> style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Area of Interest <td class="style15"> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="False" Height="30px" Width="171px"> <asp:ListItem> <asp:ListItem>C <asp:ListItem>C++ <asp:ListItem>JAVA <asp:ListItem>.NET <asp:ListItem>PHP <asp:ListItem>VOICE <asp:ListItem>NON-VOICE <asp:ListItem>MAINFRAME <asp:ListItem>Others... </td> </td></tr> <tr> <td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Years of Experience </td> <td class="style2"> <asp:TextBox ID="txt_yoe" runat="server" MaxLength="2" Width="24px"> </td> </tr> <tr> <td class="style3" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Mobile</td> <td class="style4"> <asp:TextBox ID="txt_mbno" runat="server" Height="23px" MaxLength="3" ReadOnly="True" style="margin-top: 0px" Width="56px">+91 <asp:TextBox ID="txt_mobile" runat="server" MaxLength="10" Width="117px" > </td> </tr> <tr> <td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> E-mail ID</td> <td class="style8"> <asp:TextBox ID="txt_email" runat="server" Width="184px"> </td> </tr> <tr> <td class="style5" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Address</td> <td class="style6"> <asp:TextBox ID="txt_address" runat="server" Height="90px" TextMode="MultiLine" Width="184px"> </td> </tr> <tr> <td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Country</td> <td class="style2"> <asp:TextBox ID="txt_country" runat="server" Width="184px"> </td> </tr> <tr> <td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> City</td> <td class="style2"> <asp:TextBox ID="txt_city" runat="server" Width="184px"> </td> </tr> <tr> <td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> State</td> <td class="style2"> <asp:TextBox ID="txt_state" runat="server" Width="184px"> </td> </tr> <tr> <td class="style9" style="font-family: 'raavi'; font-size: large; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #5F5F5F" align="justify"> Upload Resume</td> <td class="style2"> <asp:FileUpload ID="uploadResume" runat="server" Height="29px" Width="218px" /> <td> </td> </td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td align="center" class="style1" colspan="2"> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" OnClientClick="return validate();" Text="Submit" Height="36px" /> <br /> <br /> </td> </tr> </table> </div> </div> </div>
my C# code is
my C# code is
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.Xml;
using System.IO;
public partial class RegisterationForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lbl_date.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
lbl_date.Text = DateTime.Today.ToShortDateString();
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("formxml.xml"));
XmlElement parentelement = xmldoc.CreateElement("registeration");
XmlElement Date = xmldoc.CreateElement("Date");
Date.InnerText = lbl_date.Text;
XmlElement Name = xmldoc.CreateElement("Name");
Name.InnerText = txt_name.Text;
XmlElement Qualification = xmldoc.CreateElement("Qualification");
Qualification.InnerText = droplst_qulification.Text;
XmlElement areaofinterest = xmldoc.CreateElement("areaofinterest");
areaofinterest.InnerText = DropDownList1.Text;
XmlElement yearofexperience = xmldoc.CreateElement("yearofexperience");
yearofexperience.InnerText = txt_yoe.Text;
XmlElement Mobile = xmldoc.CreateElement("Mobile");
Mobile.InnerText = txt_mobile.Text;
XmlElement EmailID = xmldoc.CreateElement("EmailID");
EmailID.InnerText = txt_email.Text;
XmlElement Address = xmldoc.CreateElement("Address");
Address.InnerText = txt_address.Text;
XmlElement Country = xmldoc.CreateElement("Country");
Country.InnerText = txt_country.Text;
XmlElement City = xmldoc.CreateElement("City");
City.InnerText = txt_city.Text;
XmlElement state = xmldoc.CreateElement("state");
state.InnerText = txt_state.Text;
string pathname ="C:\\Documents and Settings\\Sweet Pc\\Desktop\\WebSite12\\uploadResume\\";
string filename = uploadResume.FileName;
string fullpath = pathname + filename;
XmlElement Resume = xmldoc.CreateElement("Resume");
Resume.InnerText = fullpath;
parentelement.AppendChild(Date);
parentelement.AppendChild(Name);
parentelement.AppendChild(Qualification);
parentelement.AppendChild(areaofinterest);
parentelement.AppendChild(yearofexperience);
parentelement.AppendChild(Mobile);
parentelement.AppendChild(EmailID);
parentelement.AppendChild(Address);
parentelement.AppendChild(Country);
parentelement.AppendChild(City);
parentelement.AppendChild(state);
parentelement.AppendChild(Resume);
xmldoc.DocumentElement.AppendChild(parentelement);
xmldoc.Save(Server.MapPath("formxml.xml"));
uploadResume.SaveAs(Server.MapPath("uploadResume\\" + uploadResume.FileName));
txt_name.Text = "";
droplst_qulification.Text = "";
DropDownList1.Text = "";
txt_yoe.Text = "";
txt_mobile.Text = "";
txt_email.Text = "";
txt_address.Text = "";
txt_country.Text = "";
txt_city.Text = "";
txt_state.Text = "";
}}
my xml file is
my xml file is
<registeration>
<date>
</date>
<name>
</name>
<qualification>
</qualification>
<areaofinterest>
</areaofinterest>
<yearofexperience>
</yearofexperience>
<mobile>
</mobile>
<emailid>
</emailid>
<address>
</address>
<country>
</country>
<city>
</city>
<state>
</state>
<resume>
</resume>
<registeration>
<date>8/1/2013</date>
<name>Rajesh</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C</areaofinterest>
<yearofexperience>7</yearofexperience>
<mobile>576</mobile>
<emailid>hsdof</emailid>
<address>sflvjl</address>
<country>sjf</country>
<city>jflsvg</city>
<state>jdpsvj</state>
<resume> C:\Documents and Settings\Administrator\Desktop\older\phoenix\uploadresume\Rajesh Resume (2).doc</resume>
</registeration>
<registeration>
<date>8/1/2013</date>
<name>rt</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C++</areaofinterest>
<yearofexperience>t</yearofexperience>
<mobile>tryr</mobile>
<emailid>fghf</emailid>
<address>gfh</address>
<country>fgh</country>
<city>fghmk</city>
<state>gfh</state>
<resume> C:\Documents and Settings\Administrator\Desktop\older\phoenix\uploadresumeRajesh Resume (2).doc</resume>
</registeration>
<registeration>
<date>8/1/2013</date>
<name>post</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C++</areaofinterest>
<yearofexperience>7</yearofexperience>
<mobile>8888888888</mobile>
<emailid>8</emailid>
<address>88</address>
<country>nhu</country>
<city>hu</city>
<state>hu</state>
<resume>C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\Rajesh Resume (2).doc</resume>
</registeration>
<registeration>
<date>8/7/2013</date>
<name>ram</name>
<qualification>B.E(Electronics and Communication)</qualification>
<areaofinterest>JAVA</areaofinterest>
<yearofexperience>2</yearofexperience>
<mobile>56786785</mobile>
<emailid>redfg</emailid>
<address>erg</address>
<country>efdgh</country>
<city>refgd</city>
<state>dfsg</state>
<resume>C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\SIVARAJ.doc</resume>
</registeration>
<registeration>
<date>8/7/2013</date>
<name>rewr</name>
<qualification>B.E(Computer Science Engineering)</qualification>
<areaofinterest>C</areaofinterest>
<yearofexperience>4</yearofexperience>
<mobile>567457</mobile>
<emailid>rgfh</emailid>
<address>fgsnb</address>
<country>dgshn</country>
<city>dsgfh</city>
<state>dfsh</state>
<resume>C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\SIVARAJ.doc</resume>
</registeration>
</registeration>
i want to save the file in folder \"C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume\"
pls suggest me
i want to save the file in folder "C:\Documents and Settings\Sweet Pc\Desktop\WebSite12\uploadResume"
pls suggest me
Refer - FileUpload.SaveAs Method[^].
Refer - FileUpload.SaveAs Method[^].
The SaveAs method saves the contents of an uploaded file to a specified pa th on the Web server.
The SaveAs method saves the contents of an uploaded file to a specified path on the Web server.
string savePath = "c:\\temp\\uploads\\";
// Other codes....
FileUpload1.SaveAs(savePath);
So, you can do like below...
So, you can do like below...
string pathname ="C:\\Documents and Settings\\Sweet Pc\\Desktop\\WebSite12\\uploadResume\\";
// Your other codes.....
uploadResume.SaveAs(pathname);
这篇关于我想用asp.net上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!