Reputation: 10134
I am working on a winforms app using C# and wanted to add a save feature to a few parts where the user would be bale to enter text into a textbox and have it saved for next time.
how is this implemented in winforms? I am trying a local xml file and failing to persists the text while being able to read it. data.xml is the local file in my project root folder.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"(full path)\visual studio 2015\Projects\My_helper\data.xml");
string subject = xmlDoc.DocumentElement.SelectSingleNode(@"./content/reminder_email/subject").InnerText.ToString();
string body = xmlDoc.DocumentElement.SelectSingleNode(@"./content/reminder_email/body").InnerText.ToString();
Upvotes: 0
Views: 1279
Reputation: 11025
The XML approach is a good one, I've used it a lot. But beware where you choose to store it. For instance, if your application is installed to ProgramFiles
, you won't be able to write there. You'd have to store it in ProgramData
, or in the user's space.
As for the application settings, it's not really a bad way to go, but it's also not meant to be data storage. So if it's really data you're storing, use something meant for that purpose: a database or at least XML.
Upvotes: 0
Reputation: 778
Using settings is probably the easiest approach.
Read: https://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx
Don't forget to call Properties.Settings.Default.Save(); after changing a setting.
Upvotes: 1