using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.IO;

namespace XMLRead
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnQuit_Click(object sender, EventArgs e)
        {
            // End the application.
            Close();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            // Define the document outside the try block.
            XDocument NewDoc = new XDocument();

            // Tell the application to try the operation.
            try
            {
                // Read the document from disk.
                NewDoc = XDocument.Load(
                    Environment.GetFolderPath(
                        Environment.SpecialFolder.DesktopDirectory) +
                    "\\XMLSave.XML");
            }
            catch (FileNotFoundException exception)
            {
                MessageBox.Show("The " + exception.FileName + "is missing.\r\n" +
                    "Did you accidentally delete it?");
            }

            // Display the result on screen.
            txtOutput.Text = NewDoc.Declaration + "\r\n" + NewDoc.ToString();
        }
    }
}
