In my project I need to read a csv file and convert it into xml and save the xml to database table. I want to save the xml Output directly to database without saving to a file.
I was able to convert csv to xml, but I am not sure how to save it(without saving to a file)
database directly. Any help is appreciated.
Here is my code
var lines = System.IO.File.ReadAllLines(@"C:\test.csv");
var xml = new XElement("TopElement",
lines.Select(line => new XElement("Item",
line.Split(';')
.Select((column, index) => new XElement("Column" + index, column)))));
// XmlTextReader reader = new XmlTextReader(xml.ToString());
//xml.Save(@"C:\xmloutput.xml); // dont want to save to file.
Do you have column of type “XMl” in database in case you are using SQL Server?
You can check Save XML directly to Database with C#