0

I am trying to find a way to determine which operating system a user has (i.e. win7, or xp) from the App.Config file in my C# windows console application project. I currently have it working programatically in the .cs file but I cannot seem to locate any information on whether it is possible or not. Idealy I would have a setting in the config file that will specify which network location to use for grabbing files to copy to the local machine. This will make the code independent of the operating system version.

Leigh
  • 28,765
  • 10
  • 55
  • 103
SteveAnselment
  • 634
  • 3
  • 10
  • 29
  • 1
    what do you mean? App.config is a data file, it can't "do" things. – argaz Jun 27 '13 at 20:56
  • how else would it be possible to determine OS version without doing it in the .cs? I am really very new to working with the App.config file so any information i can soak up about it is greatly appreciated. – SteveAnselment Jun 27 '13 at 20:58
  • why is doing it in the .cs not good enough? the app.config file is just a convenient way of storing settings. – argaz Jun 27 '13 at 21:03
  • the Idea is to make it where once the rest of the company upgrades to win7 or even win8 there will not be a need to change the code, only change the config file. – SteveAnselment Jun 27 '13 at 21:05
  • 1
    what about storing the path that you want in the config file and use that path in code without checking the os? – argaz Jun 27 '13 at 21:11
  • What I ended up doing was leaving the version checking in the code and saved alternate file paths in the config file in order to take the hardcoded paths out of the code. Will still have to change code once OS gets upgraded out of programs scope but atleast it leaves the freedom of being able to change network locations without changing the code, just the config will need to be changed. Thanks a bunch @argaz for your input!!! – SteveAnselment Jun 28 '13 at 14:55

1 Answers1

2

If you just want to map windows versions to paths you can make a custom config section that would look like that: (I'm basing the version numbers on this answer)

<pathsByVersionSection>
    <pathsByVersion>
        <version major="5" minor="1" path="xp-path" />
        <version major="6" minor="1" path="win7-path" />
    </pathsByVersion>
</pathsByVersionSection>

and if windows 8 is added you will be able to add an element:

<version major="6" minor="2" path="win8-path" />

An example of making a custom config section with a collection can be found here

Community
  • 1
  • 1
argaz
  • 1,458
  • 10
  • 15