private bool ExportXML(string filepath)
{
bool flag = true;
try
{
XDocument doc = new XDocument();
XElement xBoot = new XElement("Sponorships");
for (int i = 0; i < dt.Rows.Count; i++)
{
XElement xe = new XElement("Sponsorship");
for (int j = 0; j < dt.Columns.Count; j++)
{
XElement xe2 = new XElement(dt.Columns[j].ColumnName.ToString(), dt.Rows[i][j].ToString());
xe.Add(xe2);
}
xBoot.Add(xe);
}
doc.Add(xBoot);
doc.Save(filepath);
}
catch (Exception)
{
flag = false;
}
return flag;
}
C#WInform 从DataTable中导出XML文件
本文转载:CSDN博客