Breaking News
Loading...
Monday, 10 December 2012

How to create new xml file in C#,Net

First make form like:




//////////////////   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();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            XmlTextWriter xmlwrt = new XmlTextWriter("C:\\Users\\Nirav\\Desktop\\people1.xml", Encoding.UTF8);
            xmlwrt.Formatting = Formatting.Indented;
            xmlwrt.WriteStartElement("people");
            xmlwrt.WriteStartElement("person");

            xmlwrt.WriteStartElement("name");
            xmlwrt.WriteString(textBox1.Text);
            xmlwrt.WriteEndElement();

            xmlwrt.WriteStartElement("age");
            xmlwrt.WriteString(numericUpDown1.Value.ToString());
            xmlwrt.WriteEndElement();

            xmlwrt.WriteStartElement("email");
            xmlwrt.WriteString(textBox3.Text);
            xmlwrt.WriteEndElement();

            xmlwrt.WriteEndElement();
            xmlwrt.WriteEndElement();

            xmlwrt.Close();

        }


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





--  Now click on button this will create file on desktop like .............




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

0 comments:

Post a Comment

Thanks for comment

 
Toggle Footer