4 Replies - 3058 Views - Last Post: 14 February 2012 - 12:52 PM Rate Topic: -----

#1 s_mostafa_h  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-May 08

Export DataGridView to XML File without any DataSet or DataTable ...

Posted 14 February 2012 - 09:29 AM

Hi All !
I want to save or Export the content(Row And Column Cell) of a DatGridView To a XML file .how can i do it ? there is No DataSet Or DataTable for DataGridView .
thanks in advance for any Help !
Is This A Good Question/Topic? 0
  • +

Replies To: Export DataGridView to XML File without any DataSet or DataTable ...

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8964
  • View blog
  • Posts: 33,624
  • Joined: 12-June 08

Re: Export DataGridView to XML File without any DataSet or DataTable ...

Posted 14 February 2012 - 09:33 AM

Navigate through the rows and columns using a for loop and construct the xml document by hand... that or actually back your table with a dataset and then do 'write xml'.
Was This Post Helpful? 0
  • +
  • -

#3 s_mostafa_h  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-May 08

Re: Export DataGridView to XML File without any DataSet or DataTable ...

Posted 14 February 2012 - 11:01 AM

Thanks For Ur Reply , Here Is My Code :
            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);

                }
            }


bu I've Some Error to create an XML File !
Thanks In Advance !
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8964
  • View blog
  • Posts: 33,624
  • Joined: 12-June 08

Re: Export DataGridView to XML File without any DataSet or DataTable ...

Posted 14 February 2012 - 11:04 AM

What error?
Was This Post Helpful? 0
  • +
  • -

#5 s_mostafa_h  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-May 08

Re: Export DataGridView to XML File without any DataSet or DataTable ...

Posted 14 February 2012 - 12:52 PM

it doesn't create any XML File !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1