Click to See Complete Forum and Search --> : read and edit text file


bhuraasif
July 24th, 2006, 02:34 AM
Dear

I want code to read a text files and adding something to that. i want to write same file after being made some changes to that files.

Please help me out

I tried like this

TextReader tr = new StreamReader("myappcounter.txt");
string i =tr.ReadLine();
i = i+1;
TextWriter te = new StreamWriter("myappcounter.txt");
te.WriteLine(i);
te.Close();
tr.Close();

as per my code it read perfectly.

but it doesnt add value.

as example in my text file there is value 5 when i add to '' i=i+1 ".

it doesnt become 6 but it becomes 51.


one more problem when debugging goes to bolded line

it gives me error like access denied

please help me and send me some code

Actually i want to create counter

Regards,
ASIF

Alsvha
July 24th, 2006, 03:39 AM
That is because "i" is a string.
So if you have a string consiting of 5 and you "add" 1 to it, you concatenate it to "5"+"1" = "51"
What you need - if you want to have the number, is to cast your string "i" to an integer (or what ever type you need)