Help Required in File Operations.
-
HI , I am developing a small application in which C# reads a file make changes to it and saves it. The txt files contains dome configuration values say
TimeOut=30 ID=abcd Scope=Allowed . . .
1.In my screen i also want to show these values, so what is the method to fetch individual values 2.When i make any change to the value i want it to be saved in that particular line itself. Thanks in Advance.Deepak Surana
-
HI , I am developing a small application in which C# reads a file make changes to it and saves it. The txt files contains dome configuration values say
TimeOut=30 ID=abcd Scope=Allowed . . .
1.In my screen i also want to show these values, so what is the method to fetch individual values 2.When i make any change to the value i want it to be saved in that particular line itself. Thanks in Advance.Deepak Surana
Why are you using an ini file and not XML ?
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Why are you using an ini file and not XML ?
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
I'm not saying that INI files are the be all and end all of config files, but they are a *lot* easier for novice users to edit, compared to XML files.
Cheers, Vikram.
"real dictators don't loose[sic] elections." - Diego Moita.
-
HI , I am developing a small application in which C# reads a file make changes to it and saves it. The txt files contains dome configuration values say
TimeOut=30 ID=abcd Scope=Allowed . . .
1.In my screen i also want to show these values, so what is the method to fetch individual values 2.When i make any change to the value i want it to be saved in that particular line itself. Thanks in Advance.Deepak Surana
deepaks3 wrote:
1.In my screen i also want to show these values, so what is the method to fetch individual values
You can read the values into a dictionary like this:
Dictionary<string, string> values = new Dictionary<string, string>();
foreach (string line in File.ReadAllLines(fileName)) {
string[] data = line.Split('=');
if (data.Length == 2) values.Add(data[0], data[1]);
}To read a value from the dictionary:
string id = values["ID"];
deepaks3 wrote:
2.When i make any change to the value i want it to be saved in that particular line itself.
Files are not line based, so you can't change a single line in a file. It's possible to update the file from that line and forward, but it's complicated. Just rewrite the entire file.
Despite everything, the person most likely to be fooling you next is yourself.