Note that there are some explanatory texts on larger screens.

plurals
  1. POmaster reset - clear listview and data from xml file
    primarykey
    data
    text
    <p>I have got a listview filled with contacts and a XML file where the contacts are stored. </p> <p>I would like to create a button which would act as a kind of Master Reset button. Basically, when the button is pressed the program (data) should reset and act like it was turned on for the first time - no contacts should be there. So, the listview should be cleared and data should be removed from the XML file. </p> <p>This is how my XML file (Contacts.xml) looks like:</p> <pre><code>&lt;People&gt; &lt;Person&gt; &lt;Name&gt;John&lt;/Name&gt; &lt;Hometown&gt;Washington&lt;/Hometown&gt; &lt;Address&gt;231 Main Street&lt;/Address&gt; &lt;Birthday&gt;130299511993682082&lt;/Birthday&gt; &lt;Phone&gt;555-555-555&lt;/Phone&gt; &lt;Email&gt;john@gmail.com&lt;/Email&gt; &lt;AdditionalInfo&gt;Skype: john.123&lt;/AdditionalInfo&gt; &lt;/Person&gt; &lt;/People&gt; </code></pre> <p>... and here is the listview (listView1):</p> <p><img src="https://i.stack.imgur.com/iPZ7v.png" alt="Listview"></p> <p>I know how to clear the listview but I have no idea how to "reset" the XML file. </p> <p>Any ideas?</p> <p>@EDIT: </p> <p>Here is what I have tried, based on your suggestions:</p> <pre><code> void MasterReset() { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string phonebook_path = path + "\\Phonebook\\Contacts.xml"; XmlDocument xDoc = new XmlDocument(); xDoc.Load(phonebook_path); XmlNode xNode = xDoc.SelectSingleNode("People"); xNode.InnerXml = ""; xDoc.Save(phonebook_path); listView1.Clear(); } </code></pre> <p>But it does not work, when I load the app again - the contacts are still there. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload