---
title: "How to get perticular record in XML file using LINQ."  
description: "How to get perticular record in XML file using LINQ."  
author: "James Smith"  
published: 2011-08-12  
updated: 2011-10-03  
canonical: https://www.mindstick.com/forum/284/how-to-get-perticular-record-in-xml-file-using-linq  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get perticular record in XML file using LINQ.

Hi,\
I have a small [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic), I have a [xml file](https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php) which contains some record, I want to [search](https://www.mindstick.com/articles/65368/best-smo-services-company-in-hyderabad-improve-search-rankings) that record using [Linq](https://www.mindstick.com/articles/12007/language-integrated-query-linq-queries) and if that [record does not exists](https://answers.mindstick.com/qa/42604/how-to-check-which-record-does-not-exists-in-one-table-to-another-table-in-sql-server) then It [return null](https://www.mindstick.com/forum/34356/facebook-email-field-return-null-even-if-the-email-permission-is-set-and-accepted) value.\
The [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) of XML file is as follows.\
<root>\
<[Employee](https://www.mindstick.com/articles/85431/remote-employee-training-tips-tricks)>\
<Name>John</Name>\
</Employee>\
<Employee>\
<Name>Jack</Name>\
</Employee>\
<Employee>\
<Name>Tori</Name>\
</Employee>\
</root>\
\
How can I perform this task....\
Help needed........\
\
Thanks.

## Replies

### Reply by Anonymous User

Thanks Awadhenra,\
This code is work for me.

### Reply by Anonymous User

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.


---

Original Source: https://www.mindstick.com/forum/284/how-to-get-perticular-record-in-xml-file-using-linq

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
