sorting xml file in ascending or descending orderhttp://forums.asp.net/t/1772921.aspx/1?sorting+xml+file+in+ascending+or+descending+orderFri, 24 Feb 2012 10:03:25 -050017729214846948http://forums.asp.net/p/1772921/4846948.aspx/1?sorting+xml+file+in+ascending+or+descending+ordersorting xml file in ascending or descending order <p>Hi Guys,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; How can i sort the xml in ascending or descending order while creating and updating xml file without using xslt and xpath.</p> <p>please help.</p> 2012-02-23T09:49:42-05:004847355http://forums.asp.net/p/1772921/4847355.aspx/1?Re+sorting+xml+file+in+ascending+or+descending+orderRe: sorting xml file in ascending or descending order <p>Use LINQ-to-XML and the sort method:</p> <p><a href="http://msdn.microsoft.com/en-us/vstudio/bb738051">http://msdn.microsoft.com/en-us/vstudio/bb738051</a></p> 2012-02-23T13:13:21-05:004848993http://forums.asp.net/p/1772921/4848993.aspx/1?Re+sorting+xml+file+in+ascending+or+descending+orderRe: sorting xml file in ascending or descending order <p>Hi,</p> <p>&nbsp; try below Code for Sorting using LINQ to XML..</p> <pre class="prettyprint">XDocument data = XDocument.Load(HttpContext.Current.Server.MapPath(&quot;~/Data/Customers.xml&quot;)); return Convert.ToInt32( (from c in data.Descendants(&quot;Customer&quot;) orderby Convert.ToInt32(c.Attribute(&quot;ID&quot;).Value) descending select c.Attribute(&quot;ID&quot;).Value).FirstOrDefault() ) &#43; 1;</pre> 2012-02-24T10:03:25-05:00