Hej! Hittade orsaken till varför de inte fungera.Hämta och spara värden med ConfigurationManager
Får inte nedanstående kod att fungera. Nästa gång koden körs så hittar den
inga värden.
Filen ('app'.exe.config) ändras inte efter att koden körts.
<code>
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
if (config.AppSettings.Settings.Count == 0)
{
//Kommer alltid hit hittar inget tidigare sparat...
path = Application.StartupPath;
}
else
{
if (config.AppSettings.Settings["OpenFileDialogPath"].Value == null)
path = Application.StartupPath;
else
{
path = config.AppSettings.Settings["OpenFileDialogPath"].Value;
if (System.IO.Directory.Exists(path) == false) path = Application.StartupPath;
}
}
}
//Hämtar det korrekta värdet för path......
if (config.AppSettings.Settings["OpenFileDialogPath"] == null)
config.AppSettings.Settings.Add("OpenFileDialogPath", path);
else
config.AppSettings.Settings["OpenFileDialogPath"].Value = path;
//Detta får jag inte att fungera:
config.Save();
</code>
Tacksam för eventuella förslag!Sv: Hämta och spara värden med ConfigurationManager
Visade inte all kod. Körde:
config.SaveAs(Application.ExecutablePath + ".config.bak");
innan jag körde config.Save();
Måste givetvis ställa tillbaka 'config.FilePath' till tidigare fil
för att den skall spara där.