DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   How to merge two text files (http://www.daniweb.com/forums/thread167459.html)

nmakkena Jan 10th, 2009 6:21 am
How to merge two text files
 
Hi

i want to merge two text files.i.e. the content of the second file has to append to the content of the first file. pls help me out

Thanks

LizR Jan 10th, 2009 6:38 am
Re: How to merge two text files
 
Firstly, think of how you would want to do it, write it down.
Work out some code that looks like it should do what you wanted.
try it, what does it do?
if it doesnt work, post it, explain what you're getting you didnt expect, and ask for assistance.

Dont post just asking for us to do it for you

ddanbe Jan 10th, 2009 6:41 am
Re: How to merge two text files
 
Open the first file with FileMode.Append.
Open the file to append with FileMode.Open.
Read the file to append into a byte array.
Write the byte array to the first file.

BlackSun Jan 10th, 2009 3:54 pm
Re: How to merge two text files
 
hi
try using namespace System.IO;you will find two classes responsible for reading and writing from file with more options are :
- StreamReader ;
- StreamWriter ;
u can read ur file using StreamReader the write it using StreamWriter
but after using ur StreamReader and Writer close them EX :
StreamReader sr = new StreamReader(Strin Path);
TextBox1.Text=sr.ReadLine();
sr.close(); ------------> close reader;

and the same with Writer ;

there is another class File contains static members
File.ReadAllText();
File.WriteAllText();
File.open(string path , filemode.append);

all these depends on ur application if u wana preview ur text file and append with another file or u wanna do ur method during procesisng ur code ;

there is more but that easy ways u can append ur txt files

bye

ddanbe Jan 10th, 2009 5:17 pm
Re: How to merge two text files
 
Quote:

Originally Posted by BlackSun
TextBox1.Text=sr.ReadLine();

ReadLine reads a file untill the next \n character, this line is then put into a textbox. Nice.
What's the relevancy with this question ?

BlackSun Jan 11th, 2009 2:56 pm
Re: How to merge two text files
 
yeah u right
but u can use method "ReadToEnd" for multiline controls

StreamReader sr = new StreamReader(---------);
TextBox1.text = sr.ReadToEnd();
so ur reader will return all readed data ......

ddanbe Jan 11th, 2009 3:18 pm
Re: How to merge two text files
 
That's very inventive BlackSun.
But if I drink wine I use a wineglass.
When I drink a coffee I use a coffeecup.
Do you drink wine from a coffeecup?
Don't use a textbox for this, but use a string.


All times are GMT -4. The time now is 4:24 am.

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