code_junkie

create your own settings in xml

Nov 13th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. AllowUserToChangePanelLayout
  2. AllowUserToDeleteCompany
  3.  
  4. <appSettings>
  5. <add key="ConnString" value="my conn string" />
  6. <add key="MaxUsers" value="50" />
  7. </appSettings>
  8.  
  9. <?xml version="1.0" encoding="utf-8" ?>
  10. <configuration>
  11. <appSettings file="ExternalWeb.config">
  12. <add key="MyKey" value="MyValue" />
  13. </appSettings>
  14. </configuration>
  15.  
  16. System.Configuration.ConfigurationManager.AppSettings["myKey"];
  17.  
  18. public static class mySettings
  19. {
  20. public enum SettingsType
  21. { UserPermitions, WebService, Alerts }
  22. public enum SectionType
  23. { AllowChangeLayout, AllowUserDelete, MaximumReturnsFromSearch, MaximumOnBatch, SendTo }
  24.  
  25. public static String GetSettings(SettingsType type, SectionType section)
  26. {
  27. return
  28. ConfigurationManager.AppSettings[
  29. String.Format("{0}_{1}",
  30. Enum.Parse(typeof(SettingsType), type.ToString()).ToString(),
  31. Enum.Parse(typeof(SectionType), section.ToString()).ToString())
  32. ];
  33. }
  34. }
  35.  
  36. <configuration>
  37. <appSettings file="myApp.config">
  38. <add key="UserPermitions_AllowChangeLayout" value="" />
  39. <add key="UserPermitions_AllowUserDelete" value="" />
  40.  
  41. <add key="WebService_MaximumReturnsFromSearch" value="" />
  42.  
  43. <add key="Alerts_SendTo" value="" />
  44. <add key="Alerts_MaximumOnBatch" value="" />
  45. </appSettings>
  46. </configuration>
  47.  
  48. <?xml version="1.0" encoding="utf-8" ?>
  49. <!--
  50. ###
  51. ### This file serves the propose of a quick configuration.
  52. ### Administrator can either change this values directly or use the
  53. ### Settings tab in the application.
  54. ###
  55. -->
  56. <appSettings>
  57.  
  58. <!-- *** User Access Configuration *** -->
  59. <!-- Allow user to change the panels layout {1: Yes} {0: No} -->
  60. <add key="UserPermitions_AllowChangeLayout" value="1" />
  61. <!-- Allow user to delete a company fro monitoring -->
  62. <add key="UserPermitions_AllowUserDelete" value="1" />
  63.  
  64. <!-- *** Web Service configuration *** -->
  65. <!-- Maximum responses from the search service -->
  66. <add key="WebService_MaximumReturnsFromSearch" value="10" />
  67.  
  68. <!-- *** Allerts configuration *** -->
  69. <!-- Send the alerts to the email writeen below -->
  70. <add key="Alerts_SendTo" value="[email protected]" />
  71. <!-- Send an alert when user import more than the number bellow -->
  72. <add key="Alerts_MaximumOnBatch" value="10" />
  73.  
  74. </appSettings>
  75.  
  76. p.value = mySettings.GetSettings(
  77. mySettings.SettingsType.WebService,
  78. mySettings.SectionType.MaximumReturnsFromSearch);
Add Comment
Please, Sign In to add comment