Looping Through Application Settings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UkhQVA==?=

    Looping Through Application Settings

    I have a Windows Form application with several application settings set. How
    is it possible for me to loop through those settings? Is it possible at all?

    Thank you



  • Bob Johnson

    #2
    Re: Looping Through Application Settings

    << Is it possible at all? >>

    No - this is logically and technically impossible.



    "RHPT" <RHPT@online.no spamwrote in message
    news:71776017-C3FE-4A4D-8C6F-B5FE657896A5@mi crosoft.com...
    >I have a Windows Form application with several application settings set.
    >How
    is it possible for me to loop through those settings? Is it possible at
    all?
    >
    Thank you
    >
    >
    >

    Comment

    • MWS

      #3
      Re: Looping Through Application Settings

      On Jul 31, 12:20 pm, RHPT <R...@online.no spamwrote:
      I have a Windows Form application with several application settings set. How
      is it possible for me to loop through those settings? Is it possible at all?
      >
      Thank you
      NameValueCollec tion settings;
      settings = System.Configur ation.Configura tionManager.App Settings;

      foreach (string keyname in settings.AllKey s)
      {
      messagebox.show (keyname)
      {

      Comment

      • Walter Wang [MSFT]

        #4
        RE: Looping Through Application Settings

        Hi,

        As MWS suggested, the Settings is of type NameValueCollec tion and you can
        use its AllKeys to iterate.

        I'm not sure if this is what you wanted. Please feel free to let us know if
        you have further questions. Thanks.


        Regards,
        Walter Wang (wawang@online. microsoft.com, remove 'online.')
        Microsoft Online Community Support

        =============== =============== =============== =====
        When responding to posts, please "Reply to Group" via your newsreader so
        that others may learn and benefit from your issue.
        =============== =============== =============== =====

        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • =?Utf-8?B?UkhQVA==?=

          #5
          Re: Looping Through Application Settings



          "MWS" wrote:
          >
          NameValueCollec tion settings;
          settings = System.Configur ation.Configura tionManager.App Settings;
          >
          foreach (string keyname in settings.AllKey s)
          {
          messagebox.show (keyname)
          {
          >
          This returns the error "The type or namespace name 'ConfigurationM anager'
          does not exist in the namespace 'System.Configu ration'. I have to use
          System.Configur ation.Configura tionSettings.Ap pSettings.

          And that does not return any of my app settings.



          Comment

          • Jesse Houwing

            #6
            Re: Looping Through Application Settings

            Hello RHPT,
            "MWS" wrote:
            >
            >NameValueColle ction settings;
            >settings = System.Configur ation.Configura tionManager.App Settings;
            >foreach (string keyname in settings.AllKey s)
            >{
            >messagebox.sho w(keyname)
            >{
            This returns the error "The type or namespace name
            'ConfigurationM anager' does not exist in the namespace
            'System.Configu ration'. I have to use
            System.Configur ation.Configura tionSettings.Ap pSettings.
            >
            And that does not return any of my app settings.
            >
            You need to add a reference to the System.Configur ation to your project.
            These classes used to reside in the .NET Core Assembly, but were moved to
            a separate assembly for .NET 2.0.

            Jesse


            Comment

            • Walter Wang [MSFT]

              #7
              Re: Looping Through Application Settings

              Hi,

              Are you using the Client Settings (created with the Settings Designer)? In
              other words, you have a strong typed settings class and you access the
              settings via strong typed property name:

              Settings.Defaul t.MyProperty


              If this is the case, then the AppSettings will not help here since it's
              using different approaches.


              To get the property name list, you can use Settings.Defaul t.Properties to
              iterate them:

              foreach (SettingsProper ty sp in Settings.Defaul t.Properties)
              {
              Console.WriteLi ne(sp.Name);
              }

              After you get the property name, then you can use reflection on the
              Settings.Defaul t object to get the property value. You can also use
              SettingsPropert y.DefaultValue to get the default value when you input in
              the settings designer.


              Regards,
              Walter Wang (wawang@online. microsoft.com, remove 'online.')
              Microsoft Online Community Support

              =============== =============== =============== =====
              When responding to posts, please "Reply to Group" via your newsreader so
              that others may learn and benefit from your issue.
              =============== =============== =============== =====

              This posting is provided "AS IS" with no warranties, and confers no rights.

              Comment

              • =?Utf-8?B?UkhQVA==?=

                #8
                Re: Looping Through Application Settings


                ""Walter Wang [MSFT]"" wrote:
                Hi,
                >
                Are you using the Client Settings (created with the Settings Designer)? In
                other words, you have a strong typed settings class and you access the
                settings via strong typed property name:
                >
                Settings.Defaul t.MyProperty
                >
                >
                If this is the case, then the AppSettings will not help here since it's
                using different approaches.
                >
                >
                To get the property name list, you can use Settings.Defaul t.Properties to
                iterate them:
                >
                foreach (SettingsProper ty sp in Settings.Defaul t.Properties)
                {
                Console.WriteLi ne(sp.Name);
                }
                >
                After you get the property name, then you can use reflection on the
                Settings.Defaul t object to get the property value. You can also use
                SettingsPropert y.DefaultValue to get the default value when you input in
                the settings designer.

                Thank you. This is what I was looking for. I should have asked my question
                better.


                Comment

                Working...