After EXTENSIVELY researching the ConfigurationManager class, I've decided to just create/read/write to my own file for the single (there will never be more than one option - the task is very specific) user-defined parameter my application will need. In my quest to 'do the right thing' as a new C#/.NET developer (from PHP), I wanted to use ConfigurationManager properly. It can't be as hard as I'm making it out to be - I'm being as honest as I can be when I say that I spent a couple of hours trying to get the settings handled via ConfigurationManager, while it took me about 5 minutes to write the attached code. It would seem to me that this task is something that many apps perform, yet I haven't found a succinct example. Not that I haven't found any examples (Here on MSDN and a few references to similar tasks on SO), but on MSDN, it sure seems like a lot of code for my requirement. At any rate.....
My app requires users to specify a path where files that are generated by the app are stored. My idea for implementation simply has the user selecting an 'Options' setting from the tool strip, selecting a folder to which the files will be stored, and saving that path to a file ([appname.exe.config] if I were using ConfigurationManager). I opted for this old-school approach:
private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = saveFileLocation.ShowDialog();
string selectedPath = saveFileLocation.SelectedPath;
System.IO.StreamWriter file = new System.IO.StreamWriter("config.ini");
file.WriteLine(selectedPath);
file.Close();
}
Notwithstanding the try/catch logic I'll add for exceptions, is there any compelling reason not to handle my needs this way? I'll need to read this file one time when the user processes their request to convert a large array of files.
I understand that the MSDN example is intended to demonstrate the flexibility of the class, but wow, it sure seemed like overkill to me. I don't want to come across as someone who needs copy/paste examples to get things done, but this seems like it would be such a common task that, again, I would have found simpler examples of how to implement my needs via ConfigurationManager.
Thanks in advance for your input.