Hi, I am trying to write a somewhat basic program to read and write to a .cfg file(text file).

Inside the .cfg file are a bunch of lines like so:

server 127.0.0.1
servername Test
server_no 1
server_group 1

etc, etc.

The first word in the line being the name and second being the value. What I am wanting to do is to read/load all of these values into separate text boxes, be able to edit them, and then save/write them back to the file(append).

What I am needing assistance with is how to read the information and write the information since the name needs to stay the same, and I just need to edit the value.

Basically I would like it to search the document, find the name string, and load whatever the value is into the text box.

Any assistance would be appreciated. Thanks.

Hi,
What could you do is use the standar "key=value" style in you configuration file.
Then you should be able to read the whole text, then split the keys & the values, by setting the seperator to be the '='. Then when you want to write back to the file, then you simply delete all the content from your file, and you write them back again, this time with the new values.

Hope i helped,
Alex :)

You could also use an INI file. I know they're a little outdated but they do come in handy in situations such as this. Take a look at this:

Working with INI Files In C#

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.