Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to export contents datagridview to an XML file

how to export contents datagridview to an XML file

Scheduled Pinned Locked Moved C#
questionxmlhelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nassimnastaran
    wrote on last edited by
    #1

    Hi All ! I want to save the content(Row And Column Cell) from a DatGridView To A XML file .how can i do it ? thanks in advance for any Help !

    A 1 Reply Last reply
    0
    • N nassimnastaran

      Hi All ! I want to save the content(Row And Column Cell) from a DatGridView To A XML file .how can i do it ? thanks in advance for any Help !

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      If you DataGridView has a datasource, then simply use the WriteXml property[^]. This[^] explains the same process with code.

      N 2 Replies Last reply
      0
      • A Abhinav S

        If you DataGridView has a datasource, then simply use the WriteXml property[^]. This[^] explains the same process with code.

        N Offline
        N Offline
        nassimnastaran
        wrote on last edited by
        #3

        thanks , but there is no database or datasource for DataGridView , the user fill only the cells and I want to save this to an XML File . thanks RGDS!

        1 Reply Last reply
        0
        • A Abhinav S

          If you DataGridView has a datasource, then simply use the WriteXml property[^]. This[^] explains the same process with code.

          N Offline
          N Offline
          nassimnastaran
          wrote on last edited by
          #4

          Here is my code , plz help me !

                  SaveFileDialog saveDialog = new SaveFileDialog();
                  saveDialog.Filter = "Xml files (\*.xml)|\*.xml";
                  saveDialog.FilterIndex = 2;
                  saveDialog.RestoreDirectory = true;
                  saveDialog.InitialDirectory = "d:\\\\";
                  saveDialog.FileName = "XML File";
                  saveDialog.Title = "XML Export";
          
                  if (saveDialog.ShowDialog() == DialogResult.OK)
                  {
                      string OutPutXMLFile = "";
                      System.Xml.XmlDocument XMLDoc = new System.Xml.XmlDocument();
                      for (int i = 0; i < DataGridView1.Rows.Count; i++)
                      {
                          OutPutXMLFile = "";
                          for (int j = 0; j < DataGridView1.Columns.Count; j++)
                              OutPutXMLFile += String.Format("{0:0.00}", DataGridView1.Rows\[i\].Cells\[j\].Value);
                          XMLDoc.CreateElement(OutPutXMLFile);
          
                      }
                  }
          

          but I've got an Error to create a xml file ! thanks !

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups