472,969 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 software developers and data experts.

Read INIFile from String or Stream


Is there any way to Read an INIFile from a string or Stream instead of a
physical file ???

I want to read the INIFile into a string then store in a db but when I read
the string from the db or save string to the db I don't want to have to copy
the string to a file to use the WritePrivateProfileString and
GetPrivateProfileString. Is there a way around this instead of writing my own
class to operate on a string or stream ???

Jul 7 '08 #1
2 5226

Maybe you can use this:

System.IO.StreamReader local_StreamReader = new
string local_text = local_StreamReader.ReadToEnd();

"sippyuconn" wrote:

Is there any way to Read an INIFile from a string or Stream instead of a
physical file ???

I want to read the INIFile into a string then store in a db but when I read
the string from the db or save string to the db I don't want to have to copy
the string to a file to use the WritePrivateProfileString and
GetPrivateProfileString. Is there a way around this instead of writing my own
class to operate on a string or stream ???

Jul 8 '08 #2
Dear Sippyucoonn,

As I understand, you store the content of the .ini file as a string in the
database, you want to read a specified key value from the string directly
If I misunderstand you, please feel free to let me know.

As far as I know there's no directly way to retrieve the key value from a
string or stream, we have to do some string operation, and it's complex to
perform the string operations if the content of the .ini file is very
large. I think you want to avoid this.

However, we have alternative ways to do this:

1. Store the data from the .ini file to a database in a more structural

For example, we can:

1). Create a table with three fields: Section, Key and Value;
2). Call the GetPrivateProfileString API to read all the section,
key and value information into this table;
3). Query the table for the setting information.

2. Use an XML file instead of .ini file to store the settings.

It's more convenience to retrieve a certain value from XML structures
than plain strings.

For exmple, we have the following content in an .ini file:



We can create an XML file to store the content instead in the following

<Section name="Section1">
<key name="key1" value="value1"/>
<key name="key2" value="value2"/>
<Secion name="Section2">
<key name="key3" value="value3"/>

Then we can store the whole content of the XML file as a single string
into the database.

Afterwards, we can take the following steps to retrieve a specify
setting entry.

1). Read the setting string from the database using SqlDataReader;
2). Create an XmlDocument object;
3). Load the setting information into the XmlDocument object by calling
the LoadXml() method;
4). Call the XmlDocument.SelectSingleNode() method to get the entry we
5). Read the value of the "value" attribute to get the value for the
specify key.

The following sample demonstrates how to do this:

private void button1_Click(object sender, EventArgs e)
//read the xml string from the database
//I just assign a specified value for example
string settings = "<Sections>" +
"<Section name=\"Section1\">" +
"<key name=\"key1\" value=\"value1\"/>" +
"<key name=\"key2\" value=\"value2\"/>" +
"</Section>" +
"<Section name=\"Section2\">" +
"<key name=\"key3\" value=\"value3\"/>" +
"</Section>" +

XmlDocument settingsXml = new XmlDocument();

string section = "Section1";
string key = "key2";

string xpath = string.Format(
section, key);
string Value = settingsXml.SelectSingleNode(


3. Use the Application Configuration File.

This is the recommended way in .NET for storing configuration

You can read the following article to get more information about the
Application Configuration.

Configuration Settings File for providing application configuration
Please don't hesitate to contact me if you have any concerns.
Zhi-Xin Ye
Microsoft Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:

Get notification to my posts through email? Please refer to

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents...
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from...
by: Just D. | last post by:
All! How should we read any file from some URL? I found in MSDN the method URLDownloadToFile function, but it's for C#. There is another example to read but it doesn't work if the page is more...
by: Harry Whitehouse | last post by:
I'm trying to obtain the load directory for my application, as well as the Windows directory on the machine, but I don't know how this is accomplished in VC++ .NET. In C# there is an Application...
by: computerwolf8 | last post by:
I have a file where I know the lines go as follows: string long string int int string double
by: markclinn | last post by:
I have a device in the field that I access by the stream method. I open the Stream and do the following: 1. stream.write a character to the device. 2. stream.read the information from the...
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
by: Jack | last post by:
Hi, I want to read a string a chars from a stream, and put it into a string. At the moment, I'm creating a buffer of a fixed size, and reading the stream of text into it. It works, but I have...
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.