Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Working with app.config in c#
//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 !");
}
}
@cosminpopescu14

This comment has been minimized.

Copy link
Owner Author

@cosminpopescu14 cosminpopescu14 commented Dec 17, 2017

Sorry for code style !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.