This
article will show you how you can read xml file content in dataset using
c#.net. This will help to convert xml data into dataset form using c#.net.
So for this demo we will first create a new web application and add a button control and generate the click event of the button control.
So for this demo we will first create a new web application and add a button control and generate the click event of the button control.
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnReadFile" runat="server" Text="Read XML
File" OnClick="btnReadFile_Click" />
</div>
</form>
</body>
|
Now we will create an xml file and add the below code.
<menu>
<menuitem Text="Main Category" url="http://www.sitename.com/maincategory.aspx"></menuitem>
<menuitem Text="Sub Category" url="http://www.sitename.com/subategory.aspx"></menuitem>
<menuitem Text="Sub Sub Category" url="http://www.sitename.com/subsubcategory.aspx"></menuitem>
</menu>
|
Now add the
below code into the button click.
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Shoping_Cart
{
public partial class ReadXML : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void
btnReadFile_Click(object sender, EventArgs
e)
{
string xmlFileName = "XMLFile.xml";
DataSet
ds = new DataSet();
ds.ReadXml(Server.MapPath(xmlFileName));
}
}
}
|
In above
code I have define the file name and created the instance of the dataset. In
dataset we have a function readxml. This function we will user to read the xml
file content by using server.mappath. Now let’s run the application by applying
the bread point on button click.
0 comments:
Please let me know your view