PDA

View Full Version : مشکل در خواندن مقادیر درج شده فایل App.config



مهیار..
چهارشنبه 12 آبان 1395, 08:57 صبح
با سلام
یک فایل App.config در برنامه دارم و بعد از سرچ بسیار تونستم راهی رو برای اعمال تغییرات در اون پیدا کنم
ولی زمانی که میخوام همون مقادیر بخونم اون مقادیر میره از فایل هایی NameProject.exe.config یا NameProject.vshost.exe.Config ... میخونه بنظرم

void ReadConfng()
{
Initialized = ConfigurationManager.AppSettings["Initialized"];
UserName = ConfigurationManager.AppSettings["username"];
Password = ConfigurationManager.AppSettings["password"];
TargetFolder = ConfigurationManager.AppSettings["TargetFolder"];


}

void WriteConfig()
{
string appPath = System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssembly().Location);
string configFile = System.IO.Path.Combine(appPath, "App.config");
ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = configFile;
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(co nfigFileMap, ConfigurationUserLevel.None);
config.AppSettings.Settings["Username"].Value = UserName;
config.AppSettings.Settings["Password"].Value = Password;
config.AppSettings.Settings["TargetFolder"].Value = TargetFolder;
config.AppSettings.Settings["Initialized"].Value = "true";
config.Save();
}


ممنون ..