XML to List of Class C#

if we have XML file like this :

<picturecollection>
  <photo>
    <name>One</name>
    <path>somepath1</path>
  </photo>
  <photo>
    <name>Two</name>
    <path>somepath2</path>
  </photo>
</picturecollection>



we can use This Code to return List of Class


XDocument xdoc = XDocument.Load(Server.MapPath(@"\Photo.xml")); List pics = (from xml in xdoc.Elements("PictureCollection").Elements("Photo") select new Pic { PicName = xml.Element("name").Value, TbPath = xml.Element("path").Value }).ToList();


        public class Pic
        {
            public string PicName {get; set;}
            public string TbPath { get; set; }
        }

Comments

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.