Last active
December 17, 2017 15:51
-
-
Save cosminpopescu14/6c94142e271f6300dc6d776f27c469c4 to your computer and use it in GitHub Desktop.
Working with app.config in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//first, let's instantiate the Configuration manager class | |
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); | |
if (ConfigurationManager.AppSettings.Count == 0) | |
{ | |
configuration.AppSettings.Settings.Add("ffmpegPath", ""); | |
configuration.Save(ConfigurationSaveMode.Full); | |
ConfigurationManager.RefreshSection("appSettings"); | |
} | |
string key = ConfigurationManager.AppSettings["ffmpegPath"]; | |
foreach (string key in ConfigurationManager.AppSettings) | |
{ | |
string value = ConfigurationManager.AppSettings[key]; | |
if (value == "") | |
{ | |
MessageBox.Show("ffpeg path not configured !"); | |
openFileDialog1.Title = "Select ffmpeg executable file"; | |
if (openFileDialog1.ShowDialog() == DialogResult.OK) | |
{ | |
string ffmpegPath = openFileDialog1.FileName; | |
//Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); | |
//configuration.AppSettings.Settings.Add("ffmpegPath", Path.GetFullPath(ffmpegPath)); | |
var settings = configuration.AppSettings.Settings; | |
settings["ffmpegPath"].Value = Path.GetFullPath(ffmpegPath); | |
configuration.Save(ConfigurationSaveMode.Full, true); | |
ConfigurationManager.RefreshSection("appSettings"); | |
} | |
} | |
else | |
{ | |
MessageBox.Show("ffmpeg path already configured !"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry for code style !