473,657 Members | 2,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read INIFile from String or Stream

Hi

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 WritePrivatePro fileString and
GetPrivateProfi leString. Is there a way around this instead of writing my own
class to operate on a string or stream ???

Thanks
Jul 7 '08 #1
2 5337
Hi

Maybe you can use this:

System.IO.Strea mReader local_StreamRea der = new
System.IO.Strea mReader("FilePa th");
string local_text = local_StreamRea der.ReadToEnd() ;
Regards
Frank

"sippyuconn " wrote:
Hi

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 WritePrivatePro fileString and
GetPrivateProfi leString. Is there a way around this instead of writing my own
class to operate on a string or stream ???

Thanks
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
afterwards.
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
way.

For example, we can:

1). Create a table with three fields: Section, Key and Value;
2). Call the GetPrivateProfi leString 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:

[Section1]
key1=value1
key2=value2

[Section2]
key3=value3

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

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

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.Sel ectSingleNode() method to get the entry we
need;
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(o bject 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>" +
"</Sections>";

XmlDocument settingsXml = new XmlDocument();
settingsXml.Loa dXml(settings);

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

string xpath = string.Format(
"/Sections/Section[@name=\"{0}\"]/key[@name=\"{1}\"]",
section, key);
string Value = settingsXml.Sel ectSingleNode(
xpath).Attribut es["value"].Value;

MessageBox.Show (Value);
}

3. Use the Application Configuration File.

This is the recommended way in .NET for storing configuration
settings.

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

Configuration Settings File for providing application configuration
data
http://www.codeproject.com/KB/dotnet/config.aspx
Please don't hesitate to contact me if you have any concerns.
Sincerely,
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:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

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
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
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

6
7351
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 written to the output stream. We are willing to pay $ to any expert (e.g. MVP) consultant who has to time to help us track down this problem. (we will discuss rates if you can prove your expertise, and problem solving approach).
3
2748
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 this app: =============================== static void Main(string args) { if (args.Length > 0) Console.SetIn(new StreamReader(args)); //executes if I don't use the "<", ">" redirection syntax when invoking XmlTextReader xmlin = new...
2
12384
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 complicated and includes not only HTML code but JAVA scripts, etc. Strange, but it doesn't work for me. // Creates an HttpWebRequest with the specified URL. HttpWebRequest myHttpWebRequest =...
11
2397
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 object which provides this type of information: IniFile=Application.ExecutablePath; Is there something comparable in VC? TIA
3
4943
by: computerwolf8 | last post by:
I have a file where I know the lines go as follows: string long string int int string double
3
1359
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 device. The problem is that when I am debugging and step through the code there is a long enough pause that I recieve the entire string. If I just run it, I only get the 1st character. I have attached the code below. Public Class Form1 ...
14
2712
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 mallocs and ect, but i removed them to help me debug. thanks. #include <stdio.h> #include <stdlib.h> #include <string.h> void freadl ( FILE *stream, char **string ) {
2
6606
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 to create a buffer of a pre-defined length: (ConstBufferByteSize=10000000). How can I read a stream into a buffer or string without knowing the number of chars the stream will contain?
0
2883
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 ?myResp.GetResponseStream() {System.Net.ConnectStream}
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.