473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Append mode in write operation

I want to write to an output file, "C:\\temp\\debu g.txt": If the file
exists, append the new content to the end of the file (instead of
overwriting the current content).

Therefore, I want to code this like below:
FileInfo lFile = new FileInfo("C:\\t emp\\debug.txt" );
if (lFile.Exists)
{

FileStream lStream =
lFile.Open(File Mode.OpenOrCrea te, FileAccess.Writ e, FileShare.Read) ;
}

However, it doesn't work because It overwrites the existing content. I
believe the append mode is defined with different parameters from the
ones I use. What are the correct parameters to define the "append"
type of write mode?

Thanks!

Oct 15 '07 #1
2 1818
Curious wrote:
I want to write to an output file, "C:\\temp\\debu g.txt": If the file
exists, append the new content to the end of the file (instead of
overwriting the current content).

Therefore, I want to code this like below:
FileInfo lFile = new FileInfo("C:\\t emp\\debug.txt" );
if (lFile.Exists)
{

FileStream lStream =
lFile.Open(File Mode.OpenOrCrea te, FileAccess.Writ e, FileShare.Read) ;
}

However, it doesn't work because It overwrites the existing content. I
believe the append mode is defined with different parameters from the
ones I use. What are the correct parameters to define the "append"
type of write mode?

Thanks!
Use FileMode.Append . You don't have to check if the file exists, if it
doesn't exist it will be created.

--
Göran Andersson
_____
http://www.guffa.com
Oct 15 '07 #2
Thanks Göran! It works!

Oct 15 '07 #3

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

Similar topics

8
9879
by: b83503104 | last post by:
Hi, I want to append one (huge) file to another (huge) file. The current way I'm doing it is to do something like: infile = open (infilename, 'r') filestr = infile.read() outfile = open(outfilename, 'a') outfile.write(filestr)
14
4762
by: Aaron Couts | last post by:
I have a program that writes to a log file. It's compiled on RH Linux 7.3 (Kernel 2.4.18-18.7). It's using fopen in append mode. When the file reaches 51200000 bytes in size, the program will no longer write to the file. When this happens, fopen and fputs do not return an error. I've been researching large file support for Linux, and it all has to do with the regular 2-gig file size limit. If it's something obvious, sorry -- I'm a C...
5
3138
by: Steven C | last post by:
Hello: I am trying to append a dataset that draws its data from a MSDE instance, and I keep getting the exception: Can't create a child list for field tblCustomers. conn = new SqlConnection("Data Source=SWC_K7\\CHRISMON1;User
1
26883
by: piotrek | last post by:
Hi. I would like to ask if there is a method to force streamwriter.writeline() to write line at the end of existing file, or should i have write the method for my own. PK
1
1761
by: Ritesh Raj Sarraf | last post by:
Hi, I've got a problem here. def compress_the_file(zip_file_name, files_to_compress, sSourceDir): """ Condenses all the files into one single file for easy transfer """ try:
2
3676
by: richardson | last post by:
I tried to open an existing file in Append mode. The file exists and also has data. file_handle := UTL_FILE.FOPEN('/usr/oracle/rdb_logs', 'pacs_report.txt', 'A'); It gives an exception utl_file.invalid_operation -"invalid operation had happened" How could this be rectified.
16
4680
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good) free hoster in Norway which doesn't use safe mode, running PHP 5.1.6 as the PHP info below shows ... Test it at: http://home.no.net/moldevbk/fopen-test/?mode=w (write - fails) http://home.no.net/moldevbk/fopen-test/?mode=a (append - ok)...
1
5803
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). If the file doesn't exist, create the file and write from the beginning. Therefore, I want to code this like below: FileInfo lFile = new FileInfo("C:\\temp\\debug.txt"); if (lFile.Exists)
15
3172
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, For some reasons, somewhere in a program, I'd like, if possible, to quickly parse a whole file before rewinding it and letting the full analysis start. My problem is that the FILE* I want do parse has been fopen'ed far away from where I am and I don't know in which MODE my FILE* has been opened. And additionally, my FILE* may not be a regular file, but a continuous
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
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
5632
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
4151
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
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1607
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.