2013-06-03 99 views
-2

我正在創建一個Windows應用程序,其中一個報告文件夾。我想當用戶設置我的應用程序用戶可以設置報告文件夾的位置,這也將保存在我的app.config文件。我怎樣才能做到這一點 ?如何設置保存在應用程序配置文件夾路徑

+0

您可以使用用戶設置,而不是將值保存在app.config文件中。請參閱[在C#中使用設置](http://msdn.microsoft.com/zh-cn/library/aa730869%28v=vs.80%29.aspx) –

+1

請在發佈之前重新閱讀您的問題。雖然語法問題在原諒中,你的問題在這裏是遠遠不可理解的 – Krishna

+0

如果你的意思是在安裝過程中看到[這個其他問題](http://stackoverflow.com/q/3925216/447356)然後使用尼爾答案在這裏存儲路徑。 –

回答

1

要修改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"); 
+0

@Neli Knight 這是我的報告路徑之一。我想在用戶設置時,他們可以選擇一條路徑,這將保存在這裏? –

相關問題