Appending the content of a text file to another text file

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

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 Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Appending the content of a text file to another text file

 
0
  #2
Dec 17th, 2008
Why not just do the writeline of body you read from the second file?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
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

Re: Appending the content of a text file to another text file

 
0
  #3
Dec 17th, 2008
Thanks for the reply Ma'am. Will it still append?
An Avalanche In D Minor
Reply With Quote Quick reply to this message  
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

Re: Appending the content of a text file to another text file

 
0
  #4
Dec 17th, 2008
Hello again, it seems it is working. I will try it with more than two text files. Thank you.
An Avalanche In D Minor
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC