i think i wasn't clear enough:).
i want to read a file line by line, and, if a certain value is found on a line, i want to change that line inside the file by adding a particular string at the end of the line. so i need to change the actual file, not a line taken out of the file.
if i use StreamReader, every time i read a line the cursor will get to the next line.
i haven't got any code since i don't know how to do it. the idea, again, is to parse a simple .txt file, find a line that contains a given searchstring and change the line inside the file. and i don't want to read all the lines in an array of strings, make the changes i need and rewrite the file. i can do this in 2 minutes if i work on a database, but i don't know how to approach the issue when working with a simple txt file.
public partial class frmFileStuff : Form
private void button1_Click(object sender, EventArgs e)
const string inFile = @"C:\file.txt";
string outFile = Path.GetTempFileName();
using (FileStream fsOut = new FileStream(outFile, FileMode.Open, FileAccess.Write))
using (StreamReader srIn = new StreamReader(inFile, Encoding.UTF8))
while ((line = srIn.ReadLine()) != null)
line += "myCustomText";
byte buffer = System.Text.ASCIIEncoding.UTF8.GetBytes(line + Environment.NewLine);
fsOut.Write(buffer, 0, buffer.Length);
thanks, sknake, but that again would imply changing unnecessary data.
from what i read so far, it seems this problem has no solution. u just need to read all the content, make changes, and rewrite the file..:-/
I Developed application in C# with crystal reports and created setup file in third party (Advance) Installer.When i installed my application on client system application is working but ...