-2
我正在创建一个Windows应用程序,其中一个报告文件夹。我想当用户设置我的应用程序用户可以设置报告文件夹的位置,这也将保存在我的app.config文件。我怎样才能做到这一点 ?如何设置保存在应用程序配置文件夹路径
我正在创建一个Windows应用程序,其中一个报告文件夹。我想当用户设置我的应用程序用户可以设置报告文件夹的位置,这也将保存在我的app.config文件。我怎样才能做到这一点 ?如何设置保存在应用程序配置文件夹路径
要修改Application.exe.config
,您需要使用ConfigurationManager
类。 这是一个代码示例:
// Open App.Config of executable
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Add an Application Setting.
config.AppSettings.Settings.Remove("UserReportPath");
config.AppSettings.Settings.Add("UserReportPath", txtUserReportPath.Text);
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
@Neli Knight
您可以使用用户设置,而不是将值保存在app.config文件中。请参阅[在C#中使用设置](http://msdn.microsoft.com/zh-cn/library/aa730869%28v=vs.80%29.aspx) –
请在发布之前重新阅读您的问题。虽然语法问题在原谅中,你的问题在这里是远远不可理解的 – Krishna
如果你的意思是在安装过程中看到[这个其他问题](http://stackoverflow.com/q/3925216/447356)然后使用尼尔答案在这里存储路径。 –