如何使用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訪問類操作
- 3. ConfigurationManager類和按需配置更改
- 4. ConfigurationManager未找到
- 5. ConfigurationManager vs變量
- 6. ConfigurationManager的替代
- 7. App.config和ConfigurationManager
- 8. 如何在類庫中使用ConfigurationManager類項目類型
- 9. c#.net ConfigurationManager壞了
- 10. envdte configurationmanager項目StartOptions
- 11. ConfigurationManager立即給出TypeInitializationException
- 12. 如何使用ConfigurationManager? (Microsoft.IdentityModel.Protocols)
- 13. 爲什麼沒有ConfigurationManager?
- 14. .NET ConfigurationManager中的app.config混亂
- 15. C#ConfigurationManager中的問題
- 16. 使用OWIN TestServer和ConfigurationManager
- 17. VS 2017中的ConfigurationManager問題
- 18. 編寫一個交叉框架類,ConfigurationManager和ConfigurationSettings
- 19. 引用程序集中的ConfigurationManager
- 20. ConfigurationManager ConnectionStrings在哪裏獲取其值?
- 21. 如何通過ConfigurationManager寫入User.Config文件?
- 22. 使用ConfigurationManager中無法讀取配置
- 23. ConfigurationManager ConnectionString拋出錯誤並返回空
- 24. 無法獲得對ConfigurationManager的引用
- 25. ConfigurationManager中不保存設置exe.config
- 26. 如何在LINQPad中模擬ConfigurationManager
- 27. 處理web.config文件 - 替代ConfigurationManager
- 28. 如何使用ConfigurationManager解析app.config?
- 29. ASP MVC - ConfigurationManager無法找到Appsettings
- 30. 檢測的appSettings的重載在ConfigurationManager中
有你來這裏之前一派? – 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