DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Appending the content of a text file to another text file (http://www.daniweb.com/forums/thread162679.html)

murderotica Dec 17th, 2008 3:46 am
Appending the content of a text file to another text file
 
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.

LizR Dec 17th, 2008 5:32 am
Re: Appending the content of a text file to another text file
 
Why not just do the writeline of body you read from the second file?

murderotica Dec 17th, 2008 10:11 pm
Re: Appending the content of a text file to another text file
 
Thanks for the reply Ma'am. Will it still append?

murderotica Dec 17th, 2008 10:19 pm
Re: Appending the content of a text file to another text file
 
Hello again, it seems it is working. I will try it with more than two text files. Thank you.


All times are GMT -4. The time now is 12:42 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC