using System;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void butRead_Click(object sender, EventArgs e)
{
lblStatus.Text = "";
}
protected void butAdd_Click(object sender, EventArgs e)
{
try
{
XDocument xmlDoc = XDocument.Load(Server.MapPath("dotnetsnippets.xml"));
xmlDoc.Element("Vaibhav").Add(new XElement("Anything", new XElement("V1", v1.Text),
new XElement("V2", v2.Text)));
xmlDoc.Save(Server.MapPath("dotnetsnippets.xml"));
lblStatus.Text = "Data successfully added to XML file.";
}
catch
{
lblStatus.Text = "Sorry, unable to process request. Please try again.";
}
}
}
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void butRead_Click(object sender, EventArgs e)
{
lblStatus.Text = "";
}
protected void butAdd_Click(object sender, EventArgs e)
{
try
{
XDocument xmlDoc = XDocument.Load(Server.MapPath("dotnetsnippets.xml"));
xmlDoc.Element("Vaibhav").Add(new XElement("Anything", new XElement("V1", v1.Text),
new XElement("V2", v2.Text)));
xmlDoc.Save(Server.MapPath("dotnetsnippets.xml"));
lblStatus.Text = "Data successfully added to XML file.";
}
catch
{
lblStatus.Text = "Sorry, unable to process request. Please try again.";
}
}
}
The Default.aspx Code here --
<%@ 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 id="Head1" runat="server">
<title>XML BY VAIBHAV MAHESHWARI</title>
</head>
<body>
<br />
<br />
<br />
<br />
<fieldset style="width: 804px" align="center">
<legend>XML BY VAIBHAV MAHESHWARI</legend>
<div align="left" style="text-align: center">
<form id="form1" runat="server">
<strong>Add to XML</strong><br />
Enter Anything:<br />
<asp:TextBox ID="v1" runat="server" /><br />
Enter Anything:<br />
<asp:TextBox ID="v2" runat="server" /><br />
<br />
<asp:Button ID="butAdd" runat="server" Text="Add" onclick="butAdd_Click" /><br />
<asp:Label ID="lblStatus" runat="server" />
<br />
</form>
</div>
</fieldset>
</body>
</html>
NOTE ::::::: there must be file named dotnetsnippets.xml in the same folder and it must contain the following CODE
<?xml version="1.0" encoding="utf-8"?>
<Vaibhav>
</Vaibhav>
0 comments:
Post a Comment