如何使用COnfigurationManager類讀取和寫入設置文件?ConfigurationManager類
回答
我可以嘗試並給你細分,但真的以下鏈接,全部由Jon Rista編寫,是我發現的有關System.Configuration命名空間的最佳資源。
Unravelling the Mysteries of .NET 2.0 Configuration
感謝您的鏈接。最終的鏈接包含對machine.config文件的引用。該文件包含我在下面的SpaceCracker評論中提到的「流氓」字符串。我相信我已經想出了.NEt可執行文件的配置管理系統。 – abhi 2010-07-18 13:33:31
檢查以下
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
http://www.codeproject.com/KB/cs/SystemConfiguration.aspx
我遇到的一件事是,當我通過connectionstrings部分執行循環時,會出現一個流氓字符串,我不知道這個流氓字符串是如何填充的。例如,我的連接字符串部分有 a> prod b> dev c>其中包含字符串 。 當我通過connectionStrings節循環時,使用此代碼。 (ConfigurationManager.ConnectionStrings中的ConnectionStringSettings鍵) Console.WriteLine(「ConKey:{0},Value:{1}」,key.Name,key.ConnectionString.ToString()); } 我得到4個字符串。 – abhi 2010-07-17 20:54:28
一兩件事,可能會趕你出去是訪問您必須手動添加到System.Configuration參考ConfigurationManager中類。 System.Configuration命名空間被分割到多個程序集中 - 默認情況下你只能得到其中的一部分。
Space Cracker發佈了一些很好的鏈接,但也有一種方法可以編寫強類型的配置部分,我在幾年前寫了這些部分 - Configuring a .NET 2.0 Application Using the ConfigurationSection class。我從來沒有見過其他人使用過強類型的ConfigurationSections,但一旦你習慣了他們,他們非常有用。
- 1. ConfigurationManager&Static類
- 2. ConfigurationManager類和Settings類有什麼區別?
- 3. 靜態ConfigurationManager訪問類操作
- 4. ConfigurationManager中類中沒有提供
- 5. ConfigurationManager類和按需配置更改
- 6. .NET Framework 4.5中不存在ConfigurationManager類
- 7. ConfigurationManager的替代
- 8. ConfigurationManager中的WPF
- 9. App.config和ConfigurationManager
- 10. IOrchardShellEvents實現ConfigurationManager
- 11. ConfigurationManager未找到
- 12. ConfigurationManager vs變量
- 13. 如何在類庫中使用ConfigurationManager類項目類型
- 14. envdte configurationmanager項目StartOptions
- 15. C#ConfigurationManager - 子節點?
- 16. c#.net ConfigurationManager壞了
- 17. C#ConfigurationManager中的問題
- 18. ConfigurationManager中功能錯誤
- 19. .NET ConfigurationManager中的app.config混亂
- 20. VS 2017中的ConfigurationManager問題
- 21. F#試圖訪問ConfigurationManager
- 22. 爲什麼沒有ConfigurationManager?
- 23. ConfigurationManager未聲明 - 有DLL
- 24. 使用OWIN TestServer和ConfigurationManager
- 25. Azure環境下的ConfigurationManager
- 26. ConfigurationManager中的項目本身
- 27. ConfigurationManager立即給出TypeInitializationException
- 28. 如何使用ConfigurationManager? (Microsoft.IdentityModel.Protocols)
- 29. 我可以創建自定義方法ConfigurationManager中類
- 30. 編寫一個交叉框架類,ConfigurationManager和ConfigurationSettings
有你來這裏之前一派? – 2010-07-17 14:54:49
是的,我當然有。我有幾個鏈接,我試過了。我也參考Andrew Troelson編寫的一本名爲「Pro C#2008和.NET 3.5 Platform」的書。我正在嘗試那本書中的例子。這本書說,app.exe.config每次被覆蓋,我編譯。我在VS 2010中沒有遇到過這種情況。 – abhi 2010-07-17 21:24:51