p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   Reading an INI file in C# (http://p2p.wrox.com/showthread.php?t=57435)

@shish May 3rd, 2007 02:42 PM

Reading an INI file in C#
 I have this problem where i have put in data in a INI file using key value pairs....
  userName=Mr A

the problem that i am facing is that i want to use <number> as a key and assign a value ..could either be 8 or 9...from the C# code that i am using
...i have used [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key,string val,string filePath);

        private static extern int GetPrivateProfileString(string section,string key,string def, StringBuilder retVal,
            int size,string filePath);

in my C# code to access the data present.. i can access data using the regular key value pairs.. ie the userName by passing the key but simply cannot assign a value to the <number>...(which upto some extent i know must be used as a key) part of the URI.......
please could some body help me with this problem[8D]


DeborahStoddard April 1st, 2015 04:00 AM

RE: Reading an INI file in C#
I would recommend you to check out this C# library for advance processing of INI files.
It can enable you to bind your data in simple manner, you would need to define a placeholders like this: @{placeholder}

So your INI file's content would be this:

userName=Mr A

And you can execute a binding like the following:


IniFile file = new IniFile();

// This will bind placeholders with internal data.
// In other words 'number' placeholder will get 'number' key's value.

// This will bind placeholders with external data.
// In other words 'URL' placeholder will get KeyValuePair's value.
    new KeyValuePair<string, string>("URL", "example"));

// The 'email' variable's value is: https://www8.example.com
string email = file.Sections["section"].Keys["Email"].Value;

All times are GMT -4. The time now is 02:38 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.