Sponsored By
Advertise with Us
Advertisement
Advertise with Us
Follow Us
Article
Forum
Blog
Quiz
Beginner
Careers
Contact
Login
Email Id
Password
Remember Me
Forgot Password?
Sign Up
Home
|
Product
|
Services
|
About Us
|
Interview
|
DeveloperSection
|
Submit an Article
|
Submit Blog
Report Abuse Form
Reason:
Home
>>
.Net
>>
C#
>>
How to get perticular record in XML file using LINQ.
Author
Post
James Smith
Total Post:
48
Member Since:
3/16/2011
Points:
270
How to get perticular record in XML file using LINQ.
Posted On:
8/12/2011 2:03:14 AM
Report Abuse
Hi,
I have a small problem, I have a xml file which contains some record, I want to search that record using Linq and if that record does not exists then It return null value.
The format of XML file is as follows.
<root>
<Employee>
<Name>John</Name>
</Employee>
<Employee>
<Name>Jack</Name>
</Employee>
<Employee>
<Name>Tori</Name>
</Employee>
</root>
How can I perform this task....
Help needed........
Thanks.
Reply
Author
Post
Awadhendra Tiwari
Total Post:
126
Member Since:
1/19/2011
Points:
893
Re: How to get perticular record in XML file using LINQ.
Posted On:
8/12/2011 2:14:20 AM
Report Abuse
Hi James,
Use following link to solve your problem,
public class Employee
{
public string Name { get; set; }
}
at click of button event write following code.
XDocument data = XDocument.Load(HttpContext.Current.Server.MapPath("Team\\Team.xml"));
TeamDetails record = (from r in data.Elements("root").Elements("Team")
where r.Element("Id").Value.Equals(Request.QueryString["Id"].ToString())
select new TeamDetails()
{
Name = r.Element("Name").Value,
}).FirstOrDefault();
if (record != null)
{
//Display record.
}
This code might be useful for you.
Thanks.
Reply
Author
Post
Jenry Hock
Total Post:
18
Member Since:
9/7/2011
Points:
116
Re: How to get perticular record in XML file using LINQ.
Posted On:
10/3/2011 1:00:03 AM
Report Abuse
Thanks Awadhenra,
This code is work for me.
Reply
Report Abuse Form
Reason:
Total Online Users:
2888
Advertisement
Advertise with Us
Copyright ©
2013
MindStick. All Rights Reserved.
Home
|
Contact Us
|
Services
|
Feedback
|
Advertisement
|
Privacy Policy
|
Term & Conditions
|
About Us