Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Metro
how to save data taken from user in xml file and how to display same data to the user???
Posted 11-Nov-12 22:46pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
sandesh021990 at 12-Nov-12 5:20am
   
i got this article.. but how to retrieve and write into xml file in metro style app...
please help
thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I like to use an XML serializable class since it is very easy to maintain and modify. Just add the attributes above the class and properties. Then you can just serialize to an XML and deserialize your XML to an object.
 
Example:
 

using System;
using System.IO;
using System.Xml.Serialization;
 
    [XmlRoot("UserProfile")]
    public class Profile
    {
        [XmlElement()]
        public string Name { get; set; }
        [XmlElement()]
        public int Age { get; set; }
        
        public void Serialize(string uri)
        {
            if (string.IsNullOrEmpty(uri))
                throw new ArgumentNullException("File path invalid.");
 
            XmlSerializer s = new XmlSerializer(typeof(Profile));
            using (TextWriter w = new StreamWriter(uri))
            {
                s.Serialize(w, this);
                w.Close();
            }
        }
 
        public static Profile Deserialize(string uri)
        {
            if (string.IsNullOrEmpty(uri))
                throw new ArgumentNullException("File path invalid.");
 
            using (TextReader r = new StreamReader(uri))
            {
                XmlSerializer s = new XmlSerializer(typeof(Profile));
                return (Profile)s.Deserialize(r);   
            }
        }
    }
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 225
1 CHill60 170
2 Manfred R. Bihy 170
3 _Amy 155
4 Sergey Alexandrovich Kryukov 144
0 OriginalGriff 7,320
1 Sergey Alexandrovich Kryukov 6,043
2 Maciej Los 3,754
3 Peter Leow 3,448
4 CHill60 2,572


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100