I have a class XMLProfile which has the methods to write/edit/delete data into the xml file. This data is read and displayed in a listview in Visual C#
public void xmlwriter(string path)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("C:\\product.txt);
XmlNode fold = xdoc.CreateElement("Folder");
XmlNode name = xdoc.CreateElement("Name");
XmlNode rec = xdoc.CreateElement("Recurse");
name.InnerText = path;
rec.InnerText = "true";
fold.AppendChild(name);
fold.AppendChild(rec);
xdoc.SelectSingleNode("//Folders").AppendChild(fold);
xdoc.Save("C:\\product.txt");
}
The write method (Adding new data to the xml) is shown above and the delete is shown below
public void delete(string snode)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("C:\\product.txt");
foreach (XmlNode node in xdoc.SelectNodes("BackupProfile/Folders/Folder"))
{
string temp = node.SelectSingleNode("Name").InnerText;
if (temp == snode)
{
node.ParentNode.RemoveChild(node);
}
}
xdoc.Save("C:\\product.txt");
}
Similarly Edit and Reset methods.
Fromm my main program form I call these method using a button click
private void button8_Click(object sender, EventArgs e)
{
this.folderBrowserDialog1.ShowNewFolderButton = false;
this.folderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.MyComputer;
DialogResult result = this.folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
// user selected folder will be added to the XML Profile for backup
string path = this.folderBrowserDialog1.SelectedPath;
XMLProfile xml = new XMLProfile();
xml.xmlwriter(path);
listView1.Items.Add(path);
}
}
The above method is for adding a new data calling the xmlwriter method from the XMLProfile class.
It is all working fine, but now I realized it is right only to have a Apply button before the changes are finalized and saved.
How do I implement this? I used this link StackOverflow but it did not work for me actually not sure how to implement that in my project. Along with the Apply button I am having a Cancel button. Cancel: Being obvious should not save the changes and just reload the xml file going back to previously saved version.
Any help is appreciated and if any further information is needed please do ask. Thank you.