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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 576
1 OriginalGriff 183
2 Tadit Dash 170
3 Sergey Alexandrovich Kryukov 156
4 Peter Leow 130
0 Sergey Alexandrovich Kryukov 9,325
1 OriginalGriff 5,473
2 Peter Leow 4,150
3 Maciej Los 3,540
4 Abhinav S 3,333


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