RSS Forums RSS

Appending the content of a text file to another text file

Please support our C# advertiser: DiscountASP.NET – 3 Months Free on C# Web Hosting
Thread Solved
Reply
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

  #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:

string filename = @"C:\Temp.txt";
string body = null;
StreamReader sr = File.OpenText(files); 
body = sr.ReadToEnd();
StreamWriter sw = File.Create(filename);
sw.WriteLine(body);

sr = File.OpenText(files2);
body = sr.ReadToEnd();
File.AppendAllText(filename, body);

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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,734
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 184
LizR LizR is offline Offline
Posting Virtuoso

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

  #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  
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

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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C# Forum
Views: 997 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:22 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC