Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Show the dialog and get result.
            MySerializer serializer = new MySerializer();

            Person person;

            string       fileName;
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                fileName = openFileDialog1.FileName;


                StreamReader reader = new StreamReader(fileName);
                person = MySerializer.Deserialize(reader);
                reader.Close();

                this.textBoxName.Text        = person.Name;
                this.textBoxEmail.Text       = person.Email;
                this.richTextBoxAddress.Text = person.Address;
            }
            //Console.WriteLine(result); // <-- For debugging use.
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Person person = new Person();

            person.Name    = this.textBoxName.Text;
            person.Email   = this.textBoxEmail.Text;
            person.Address = this.richTextBoxAddress.Text;

            var fileResult = saveFileDialog1.ShowDialog();


            TextWriter writer = new StreamWriter(saveFileDialog1.FileName);

            MySerializer.Serialize(writer, person);

            writer.Close();
        }