connectseekers.com

Wednesday, 22 February 2017

Read Xml File in C#

2/22/2017 - By Pranav Singh 0

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.


<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.



Now check the dataset values.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top