Dear All,
I have webform with the ENo,EName,EMail,Phone text fields.
Now i need to store values into xml file which are retrieved from textfields.
Can anybody suggest me.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 2, 2012, 5:00 AM EST
Note:-Here we have to provide one value in the Xml file manually
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Saving_User_Input_Data_to_an_XML._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 Pagetitle>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Student Id" Width="100px">asp:Label>
<asp:TextBox ID="TextBox1" runat="server">asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Student Name" Width="100px">asp:Label>
<asp:TextBox ID="TextBox2" runat="server">asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Student Marks" Width="100px">asp:Label>
<asp:TextBox ID="TextBox3" runat="server">asp:TextBox><br />
<asp:Label ID="Label4" runat="server" Text="Student Address">asp:Label>
<asp:TextBox ID="TextBox4" runat="server">asp:TextBox>
div>
<br />
<asp:Button ID="btnaddrecords" runat="server" onclick="btnaddrecords_Click"
Text="Add Records" />
<asp:GridView ID="GridView1" runat="server">
asp:GridView>
<asp:Button ID="btn_showdata" runat="server" onclick="btn_showdata_Click"
Text="Show Xml Data" />
form>
body>
html>
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.Data.SqlClient;
namespace Saving_User_Input_Data_to_an_XML
{
public partial class _Default : System.Web.UI.Page
{
static DataSet ds;
static DataTable dt;
static DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ds = new DataSet();
ds.ReadXml(MapPath("data.xml"));
dt = ds.Tables["student"];
}
}
protected void btnaddrecords_Click(object sender, EventArgs e)
{
dr = dt.NewRow();
dr["sid"] = TextBox1.Text;
dr["sname"] = TextBox2.Text;
dr["smarks"] = TextBox3.Text;
dr["saddress"] = TextBox4.Text;
dt.Rows.Add(dr);
ds.WriteXml(Server.MapPath("data.xml"));
Response.Write("Record Successfully Inserted");
clear();
}
void clear()
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
protected void btn_showdata_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("data.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
Thanks