You need Flush() StreamWriter after recording.
By default, a StreamWriter is buffered, which means that it will not be displayed until it receives a Flush () or Close () call.
You can also try closing it as follows:
sw.Close(); //or tw.Flush();
You can also see the StreamWriter.AutoFlush Property
Gets or sets a value indicating whether the StreamWriter will flush its buffer into the underlying stream after each call to StreamWriter.Write.
Another option, which is now very popular and recommended, is to use the using statement , which will take care of this.
Provides convenient syntax to ensure proper use of IDisposable objects.
Example:
using(var sr = new StreamReader("C:\\Temp1\\test1.txt")) using(var sw = new StreamWriter("C:\\Temp2\\test2.txt")) { ... }
source share