943,864 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 8785
  • C# RSS
Jan 10th, 2009
0

How to merge two text files

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nmakkena is offline Offline
14 posts
since Dec 2008
Jan 10th, 2009
0

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
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Jan 10th, 2009
0

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.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Jan 10th, 2009
0

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
Reputation Points: 28
Solved Threads: 5
Light Poster
BlackSun is offline Offline
46 posts
since Feb 2008
Jan 10th, 2009
0

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 ?
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Jan 11th, 2009
0

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 ......
Reputation Points: 28
Solved Threads: 5
Light Poster
BlackSun is offline Offline
46 posts
since Feb 2008
Jan 11th, 2009
0

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.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Apr 6th, 2010
-4

Seriously?

Click to Expand / Collapse  Quote originally posted by LizR ...
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

LizR, the next time you have a question follow your own advice. I can't believe that anyone would be so arrogant as to respond with such a snobish answer. The poster, like I, likely knew how to logically handle such a task but was rather looking for a pre-existing method like, say, File.Merge(StringArrayOfPaths). If you don't have anything to contribute to a post other than ignorant statements, don't bother posting.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nareitz is offline Offline
1 posts
since Apr 2010
Apr 12th, 2010
1
Re: How to merge two text files
Actually nareitz what LizR did was the correct response. If you check the forum policy it clearly states that users should attempt to solve the problem themselves before posting. We are here to help troubleshoot, not to do all the work.
You may be right that they know how to do it themselves, if that is the case, they should post what they have and ask if there is a better way to do it.
next time you have something to say, perhaps you should read the forum rules before you lambaste a poster without good cause.
Last edited by Ryshad; Apr 12th, 2010 at 5:43 am.
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Read XML from string instead of File
Next Thread in C# Forum Timeline: Switch statement in RDLC





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC