DataTable dt = new DataTable(); DataSet ds = new DataSet(); string fileName = @"izdelia.xml"; dt = ((DataTable)dataGridView1.DataSource).Copy(); ds.Tables.Add(dt); System.IO.FileStream myFileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Create); //System.Xml.XmlTextWriter myXmlWriter = new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode); System.Xml.XmlDataDocument xmlDoc = new System.Xml.XmlDataDocument(ds); xmlDoc.DataSet.EnforceConstraints = false; System.Xml.XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); xmlDoc.PrependChild(xmlDec); System.Xml.XmlWriter xmlWriter; xmlWriter = new XmlTextWriter(myFileStream, System.Text.Encoding.UTF8); xmlDoc.WriteTo(xmlWriter); - And why don't you close (through using, of course) your stream, XmlWriter and everything else? The problem may be this. - VladD
- @VladD Exactly, but line 1 turned out like this: <? Xml version = "1.0" encoding = "UTF-8" standalone = "true"?>. How to remove standalone = "true" - SVD102
- oneOr maybe this is better: dt.WriteXml (filename); - nick_n_a
- @nick_n_a No. so worse - SVD102
- @ SVD102: This is another problem, look at the XmlWriter settings. - VladD
|