Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 3rd, 2007, 02:42 PM
Authorized User
 
Join Date: Jan 2006
Location: gangtok, Sikkim, India.
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
Reply With Quote
  #2 (permalink)  
Old April 1st, 2015, 04:00 AM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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;
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:32 PM.


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