473,717 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I append a text file to another text file

Hi,

How could I append a text file to another text file. Let's say that I have a
File1 and I want to append File2 at the end of File1, how would I do that?

TIA
Roy
Dec 8 '05 #1
2 8595
Have a look at the following code from MSDN library.

Cheers,

Denis

using System;
using System.IO;

class Test
{
public static void Main()
{
string path = @"c:\temp\MyTes t.txt";
// This text is added only once to the file.
if (!File.Exists(p ath))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText (path))
{
sw.WriteLine("H ello");
sw.WriteLine("A nd");
sw.WriteLine("W elcome");
}
}

// This text is always added, making the file longer over time
// if it is not deleted.
using (StreamWriter sw = File.AppendText (path))
{
sw.WriteLine("T his");
sw.WriteLine("i s Extra");
sw.WriteLine("T ext");
}

// Open the file to read from.
using (StreamReader sr = File.OpenText(p ath))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLi ne(s);
}
}
}
}

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:Kn******** ***********@wag ner.videotron.n et...
Hi,

How could I append a text file to another text file. Let's say that I have a File1 and I want to append File2 at the end of File1, how would I do that?

TIA
Roy

Dec 8 '05 #2

Thanks Denis it worked like a charm.

Roy
*** Sent via Developersdex http://www.developersdex.com ***
Dec 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2814
by: sm | last post by:
How to "Insert" (not append) new text segment to an existing text file? Assume that we have text file as shown below; Elvis Sofia Kylix BCB--> How to insert here? Atten BuilderX Roma
3
23953
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
2
5783
by: JMCN | last post by:
hi i have a general question regarding append queries in access 97. each week i need to update my table(tblonlinereg) with new or modified records. firstly, i import the text file into my database and then i create a basic append query that appends the new records to the table(tblonlinereg). this works great if the field is greater than the last record appended ( where: tempID > 198 ) but how would i update/append the modifications...
14
11174
by: vbMark | last post by:
Greetings, This seems like it should be simple but I can't figure out how to do this. I just want to append binary file 2 on to the end of binary file 1. Sample code please? Thanks!
3
23848
by: Macca | last post by:
Hi, I am writing some information to a text file using the TextWriter Class. However I am having problems appending data to a file that already exists and already has text in it. I just seem to be overwriting what is in the text file. Can anyone tell me what I should be doing to append text? Thanks
2
2560
by: Gaby Sandoval | last post by:
I have this code. The user can read teh record from the text file just fine. They can click the NEXT button and it reads the next record (which is just the next line from the text file). If the user makes changes to a record using the application they have to option to click the APPEND button to overwrite there changes on the file. The file has a line of text for each record....... Here is the code for when they click the APPEND...
3
2574
by: Wolfgang Meister | last post by:
I would like to append text to a file which might exist or not. What is the easiest way to open or create it depending if it exists or not and to set it into an "append" text mode?
1
4988
by: wish | last post by:
Hello, I have problem is when i append new data in text file always append at the last of the text file. Am i can append the new data in beginning of the text file? Mean when i have update data the text file and always write at the beginning of the text file and the previous data at the below of the new data.. Can anyone have idea about it? Thanks in advance...
9
11960
by: Phill W. | last post by:
VB.Net 2005 SP1 Windows Forms Application What's the fastest way to append text to a TextBox? I have an application that monitors data written to text files. It needs to scan some fairly hefty files (typically ~15MB) and scanning the file pulling out the rows I want (typically ~10,000 of them) takes /comfortably/ under three seconds. In normal usage, this application will "follow" the end of these files as they are written to, so it...
0
9348
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9109
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7981
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6648
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5970
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4478
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4739
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2545
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2120
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.