Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2007, 02:42 PM
Authorized User
 
Join Date: Jan 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading an INI file in C#

hi,
 I have this problem where i have put in data in a INI file using key value pairs....
eg.
  [section]
  userName=Mr A
  Email=https://www<number>.<URL>.com
  number=8,9
...

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);

        [DllImport("kernel32")]
        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

achhetri
__________________
achhetri
 
Old April 1st, 2015, 04:00 AM
Registered User
 
Join Date: Apr 2015
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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:

[section]
userName=Mr A
Email=https://www@{number}.@{URL}.com
number=8


And you can execute a binding like the following:

Code:
IniFile file = new IniFile();
file.Load("path-to-ini-file.ini");

// This will bind placeholders with internal data.
// In other words 'number' placeholder will get 'number' key's value.
file.ValueBinding.Bind();

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

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading ini file in XSL ROCXY XSLT 3 January 9th, 2007 04:37 AM
Reading .ini files anisurr C++ Programming 2 February 7th, 2006 05:02 PM
ini file ptop C++ Programming 0 January 30th, 2006 06:29 AM
How to Read from INI file alen Pro VB 6 2 September 3rd, 2004 06:34 AM
INI file access jlick Pro VB 6 4 November 7th, 2003 05:11 AM





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