Retrieving the Windows path and reading settings file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to read settings for another application for a very small application.
The settings are stored in a text file, and this file is stored in the
Windows directory.

How can I retrieve the path for the Windows Directory on the local machine?
How do I best read the settings in this file? The settings are in the format
[Data]
datapath=x:\xxx
[Reports]
ReportPath=x:\xxx

I can of course read it as any text file and check every line for what I
need, but there must be a better way of doing it. The settings file contains
about 200 settings, but I only need three of them for my application.
 
How can I retrieve the path for the Windows Directory on the local
machine?

One way is:
Environment.GetEnvironmentVariable("WINDIR")

How do I best read the settings in this file? The settings are in the format
[Data]
datapath=x:\xxx
[Reports]
ReportPath=x:\xxx

Looks like a plain INI file to me, unfortunately there is no support voor
INI files in the .NET base class library. You can still however use
unmanaged calls to Win32 API functions like GetPrivateProfileString

Gabriel Lozano-Morán
 
Thanks Gabriel,

That was the answer I was looking for.

Regards,

Kenneth


LOZANO-MORÃN said:
How can I retrieve the path for the Windows Directory on the local
machine?

One way is:
Environment.GetEnvironmentVariable("WINDIR")

How do I best read the settings in this file? The settings are in the format
[Data]
datapath=x:\xxx
[Reports]
ReportPath=x:\xxx

Looks like a plain INI file to me, unfortunately there is no support voor
INI files in the .NET base class library. You can still however use
unmanaged calls to Win32 API functions like GetPrivateProfileString

Gabriel Lozano-Morán
 
Back
Top