View Single Post
Join Date: Aug 2008
Posts: 169
Reputation: murderotica is an unknown quantity at this point 
Solved Threads: 2
murderotica's Avatar
murderotica murderotica is offline Offline
Junior Poster

Appending the content of a text file to another text file

 
0
  #1
Dec 17th, 2008
Hello there, I've been busy nowadays with file manipulation and I've so far I've encountered a small problem in appending the contents of a file to another file. This is what I did:

  1.  
  2. string filename = @"C:\Temp.txt";
  3. string body = null;
  4. StreamReader sr = File.OpenText(files);
  5. body = sr.ReadToEnd();
  6. StreamWriter sw = File.Create(filename);
  7. sw.WriteLine(body);
  8.  
  9. sr = File.OpenText(files2);
  10. body = sr.ReadToEnd();
  11. File.AppendAllText(filename, body);
  12.  
  13. sw.Close();

It seems that I can't append the content of files2 to my Temp.txt file after placing the contents of files. Please help. Thanks.
An Avalanche In D Minor
Reply With Quote