示例#1
0
            public List <People> GetPeopleFromXmlFile(string path)
            {
                List <People> peoples = new List <People>();

                // Load seed data file : ~/Resources/SeedData/People.xml
                XDocument xmlDoc = XDocument.Load(Path.Combine(path, PeopleSearchConstant.PeopleXmlFileName));

                // Virtual path (of a directory) on server which contains images for people.
                string imageDirectoryPath = HttpContext.Current.Server.MapPath(PeopleSearchConstant.ImageDirectoryPath);

                // Iterate over each <detail> tag in xmlDoc to get people information.
                foreach (var DetailNode in xmlDoc.Descendants(PeopleSearchConstant.DetailsNode))
                {
                    People people = new People();
                    people.FirstName   = DetailNode.Element(PeopleSearchConstant.FirstNameNode).Value;
                    people.LastName    = DetailNode.Element(PeopleSearchConstant.LastNameNode).Value;
                    people.Address     = DetailNode.Element(PeopleSearchConstant.AddressNode).Value;
                    people.Interests   = DetailNode.Element(PeopleSearchConstant.InterestsNode).Value;
                    people.DateOfBirth = Convert.ToDateTime(DetailNode.Element(PeopleSearchConstant.DateOfBirthNode).Value);
                    people.Gender      = DetailNode.Element(PeopleSearchConstant.GenderNode).Value;

                    string imageName = DetailNode.Element(PeopleSearchConstant.ImageNameNode).Value;

                    // Virtual path of image file on server for the given <imagename>
                    string imagePath = Path.Combine(imageDirectoryPath, imageName);

                    people.Image = GetImageBytes(imagePath);

                    peoples.Add(people);
                }

                return(peoples);
            }
示例#2
0
        public List <Person> GetPersonsFromXmlFile(string path)
        {
            List <Person> persons = new List <Person>();

            // Load seed data file : ~/Resources/SeedData/Person.xml
            XDocument xmlDoc = XDocument.Load(Path.Combine(path, Constants.PersonXmlFileName));

            // Virtual path (of a directory) on server which contains images for persons.
            string imageDirectoryPath = HttpContext.Current.Server.MapPath(Constants.ImageDirectoryPath);

            // Iterate over each <detail> tag in xmlDoc to get person information.
            foreach (var DetailNode in xmlDoc.Descendants(Constants.DetailsNode))
            {
                Person person = new Person();
                person.FirstName   = DetailNode.Element(Constants.FirstNameNode).Value;
                person.LastName    = DetailNode.Element(Constants.LastNameNode).Value;
                person.Address     = DetailNode.Element(Constants.AddressNode).Value;
                person.Hobbies     = DetailNode.Element(Constants.HobbiesNode).Value;
                person.DateOfBirth = Convert.ToDateTime(DetailNode.Element(Constants.DateOfBirthNode).Value);
                person.Gender      = DetailNode.Element(Constants.GenderNode).Value;

                string imageName = DetailNode.Element(Constants.ImageNameNode).Value;

                // Virtual path of image file on server for the given <imagename>
                string imagePath = Path.Combine(imageDirectoryPath, imageName);

                person.Image = GetImageBytes(imagePath);

                persons.Add(person);
            }

            return(persons);
        }