Please let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like to share? Submit it here!
You probably know how data can be read from a file. Here's how you can write data to a file from another file in C#:
using System;
using System.IO;
class AppendText
{
public static void Main(String[] args)
{
//Append the text from InputFile.txt to this file.
TextWriter outfile= File.AppendText("c:/CopytoFile.txt");
//Append text from this file to CopytoFile.txt.
TextReader infile = File.OpenText("c:/InFile.txt");
String Str;
while((Str = infile.ReadLine())!=null)
outfile.WriteLine(Str);
infile.Close();
outfile.Close();
}
}
Source: DotNetExtreme.com
This was first published in March 2003