I'm trying to save the .NET application settings file in the user folder MyDocument% \ MyApplication, but I don’t know how to check the existing folder \ file, and also create or add the folder \ file when saving, I don’t want to open saveFileDialog, because I need to so that the file is in one place on all user computers. This is what I have so far, but it does not work. Any help would be appreciated:
var saveSettings = settingsList.text; //assign settings to a variable saveSettings = Regex.Replace(saveSettings, @"\s+", "").Trim() + Environment.NewLine; //remove any extra spaces and add a carriage return so that each setting is on a new line var fileName = string.Format("{0}\\{1}", Environment.SpecialFolder.MyDocuments + "\\MyApp\\", "settings.dat"); //generate path to settings.dat File.AppendAllText(fileName, saveSettings); //save settings.dat
Jeagr
source share