RSS Forums RSS

How to merge two text files

Please support our C# advertiser: DiscountASP.NET – 3 Months Free on C# Web Hosting
Reply
Posts: 13
Reputation: nmakkena is an unknown quantity at this point 
Solved Threads: 0
nmakkena nmakkena is offline Offline
Newbie Poster

How to merge two text files

  #1  
Jan 10th, 2009
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
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: How to merge two text files

  #2  
Jan 10th, 2009
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
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: 1,223
Reputation: ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice 
Solved Threads: 163
ddanbe's Avatar
ddanbe ddanbe is online now Online
Nearly a Posting Virtuoso

Re: How to merge two text files

  #3  
Jan 10th, 2009
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.
"If you judge people, you have no time to love them." Mother Teresa
Make love, no war. Cave ab homine unius libri.
First rule of debugging: "If you get a different error message, you're making progress."
Danny
Reply With Quote  
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

Re: How to merge two text files

  #4  
Jan 10th, 2009
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
Reply With Quote  
Posts: 1,223
Reputation: ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice 
Solved Threads: 163
ddanbe's Avatar
ddanbe ddanbe is online now Online
Nearly a Posting Virtuoso

Re: How to merge two text files

  #5  
Jan 10th, 2009
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 ?
"If you judge people, you have no time to love them." Mother Teresa
Make love, no war. Cave ab homine unius libri.
First rule of debugging: "If you get a different error message, you're making progress."
Danny
Reply With Quote  
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

Re: How to merge two text files

  #6  
Jan 11th, 2009
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 ......
Reply With Quote  
Posts: 1,223
Reputation: ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice 
Solved Threads: 163
ddanbe's Avatar
ddanbe ddanbe is online now Online
Nearly a Posting Virtuoso

Re: How to merge two text files

  #7  
Jan 11th, 2009
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.
"If you judge people, you have no time to love them." Mother Teresa
Make love, no war. Cave ab homine unius libri.
First rule of debugging: "If you get a different error message, you're making progress."
Danny
Reply With Quote  
Reply

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



Views: 1448 | Replies: 6 | 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 2:47 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