How to Edit Xml file in C#.Net


First Make Form Like



Node write code for both button "open " and "save"


///////////////////////////   CODE   ////////////////////////////////


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

namespace Xml_File_Operation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        XmlDocument xdoc1;
        string path;

        private void btnopen_Click(object sender, EventArgs e)
        {

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "XML |*.xml";
            if (ofd.ShowDialog() == DialogResult.OK)
            {

                path = ofd.FileName;
                xdoc1 = new XmlDocument();
                xdoc1.Load(path);
                textBox2.Text = path;
                textBox1.Text = xdoc1.SelectSingleNode("people/person/name").InnerText;

                numericUpDown1.Value = Convert.ToInt32(xdoc1.SelectSingleNode("people/person/age").InnerText);

                textBox3.Text = xdoc1.SelectSingleNode("people/person/email").InnerText;


            }


        }

        private void btnsave_Click(object sender, EventArgs e)
        {

            xdoc1.SelectSingleNode("people/person/name").InnerText = textBox1.Text;
            xdoc1.SelectSingleNode("people/person/age").InnerText = numericUpDown1.Value.ToString();
            xdoc1.SelectSingleNode("people/person/email").InnerText = textBox3.Text;
            xdoc1.Save(path);

        }
   }
}

///////////////////////////////////////////////////////////////////////////////////////////////////


-  click on open button.
-  selext xml file to open.
-  edite it whith texbox anmd other conntrol.
-  Click on save button.


///////////////////////   OUTPUT   //////////////////////


Now you can show that your file hhow is converted............



                               





--
/\/ir@\/  <(.'.)>

Comments

Post a Comment

Popular posts from this blog

How to make and use web service in Microsoft Dynamics Navision.

How to use Format function in Microsoft Dynamics Navision.

How to create simple report in Microsoft Dynamics Navision.