Override line in file while writing
<p>I am reading a file using streamreader opened in ReadWrite mode. The requirement I have is to check for a file for specific text, and if it is found, replace that line with a new line. </p>

<p>Currently I have initialized a <code>StreamWriter</code> for writing.</p>

<p>It is writing text to a file but it's appending that to a new line.</p>

<p>So what should I do to replace the particular line text?</p>

<pre><code>System.IO.FileStream oStream = new System.IO.FileStream(sFilePath, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read); 
System.IO.FileStream iStream = new System.IO.FileStream(sFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); 

System.IO.StreamWriter sw = new System.IO.StreamWriter(oStream);
System.IO.StreamReader sr = new System.IO.StreamReader(iStream); 

string line;
int counter = 0;
while ((line = sr.ReadLine()) != null)
{
    if (line.Contains("line_found"))
    {
        sw.WriteLine("line_found false");
        break;
    }
    counter++;
}
sw.Close();
sr.Close();
</code></pre>
