title: Persisting file path between runs in c#
body: <p>I have an app in which the user needs to access certain files in a user set and selected folder.
  The folder and files paths need to be easily accessed (short simple path).
  I use the Properties Settings to hold the Folder and File paths, but for some reason each time I re-start the program the Folder and File paths are lost.
  I have followed and checked the program and all seems to be OK (except something I am missing, apparently).
  I attach here the program snippet in two parts: The search for path and the setting in case path / file not found. (removed exception handling to save on lines)</p>
  <pre><code>     public Main()   //part of Main, stripped off exception handling)
      {
          //..........
  
          dataFolder = Properties.Settings.Default.dataFolder;
          if (!Directory.Exists(dataFolder))
          {
              SetDataFolder();
          }
          configFile = Properties.Settings.Default.configFile;
          if (!File.Exists(configFile))
          {
              SetConfigFile();
          }
  
          dataFile = Properties.Settings.Default.dataFile;
          if (!File.Exists(dataFile))
          {
              SetDataFile();
          }
          
          loadParamsFromFile(configFile);  //Load the previously saved controls.
  </code></pre>
  <hr />
  <pre><code>      public String SetDataFolder()
      {
              FolderBrowserDialog dialog = new FolderBrowserDialog();
              DialogResult folder = dialog.ShowDialog();
              if (folder == DialogResult.OK)
              {
                  dataFolder = dialog.SelectedPath;
                  Directory.CreateDirectory(dataFolder);
                  dataFolder = Path.GetFullPath(dataFolder);
                  Properties.Settings.Default.dataFolder = dataFolder;
                  Properties.Settings.Default.Save();
                  return dataFolder;
              }
              else return null;
        }
      private string SetDataFile()
      {
              dataFile = $&quot;{dataFolder}\\{textBoxSampleID.Text.Replace(&quot;/r&quot;, &quot;&quot;).Trim()}.txt&quot;;
              File.Create(dataFile).Close();
              Properties.Settings.Default.dataFile = dataFile;
              Properties.Settings.Default.Save();
              return dataFile;
       }
  
      private string SetConfigFile()
      {
          configFile = $&quot;{dataFolder}\\electroplating.cfg&quot;;
          File.Create(configFile).Close();
          Properties.Settings.Default.configFile = configFile;
          Properties.Settings.Default.Save();
          return configFile;
      }
  </code></pre>