{
DataTable dt = new DataTable();
dt = FeatureAlbum.GetAlbums();
string path;
path = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + FileName + ".xml";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.IO.FileInfo fileName = new System.IO.FileInfo(path);
try
{
if (!fileName.Exists)
{
StreamWriter sw = new StreamWriter(path, true);
sw.WriteLine("
sw.WriteLine("
sw.Flush();
sw.Close();
}
doc.Load(path);
XmlElement newElem;
XmlElement newChElem;
XmlElement newSuperChElem;
XmlNode XNode;
for (int i = 0; i < dt.Rows.Count; i++)
{
newElem = doc.CreateElement("image");
doc.DocumentElement.AppendChild(newElem);
// newElem.SetAttribute("","");
newChElem = doc.CreateElement("filename");
newChElem.InnerText = dt.Rows[i]["Name"].ToString();
newElem.AppendChild(newChElem);
newChElem = doc.CreateElement("caption");
newChElem.InnerText = dt.Rows[i]["Description"].ToString();
newElem.AppendChild(newChElem);
}
//newChElem = doc.CreateElement("Time");
//newChElem.InnerText = "Time";
//newElem.AppendChild(newChElem);
XmlTextWriter writer = new XmlTextWriter(path, System.Text.Encoding.ASCII);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
writer.Close();
}
catch (Exception ex)
{
//Your Catch block here...
}
}

No comments:
Post a Comment