connectseekers.com

Tuesday, 28 February 2017

Linq to XML Examples C# Where Clause

2/28/2017 - By Pranav Singh 0

This article will show you can user linq to xml using c#. In this I have shown how you can read xml and apply filter using linq by c#.

So for this article first we will prepare an XML file.

<menu>
  <menuitem Text="Main Category" Id='1'></menuitem>
  <menuitem Text="Sub Category" Id='2'></menuitem>
  <menuitem Text="Sub Sub Category" Id='3'></menuitem>
</menu>

After this please check the code.

string xmlFileName = "XMLFile.xml";
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath(xmlFileName));

            //Now we will find value for Id 1 bypplying linq query with where clause
            var filterData = ds.Tables[0].AsEnumerable().Where(m => m.Field<string>("Id") == "1");

In above code I have first read the xml file and then apply the filter. You must check one thing in where clause, in m.Field datatype I have taken string. If you take int it will throw casting error.

Now lets check the dataset values.



Now check the value after applying filter.


Tags: , ,
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