473,654 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Append to the end of file when "write"

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). 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:\\t emp\\debug.txt" );

if (lFile.Exists)
{
// What's the syntax to append new content (instead of
overwriting the existing content?
FileStream lStream =
lFile.Open(File Mode.OpenOrCrea te, FileAccess.Writ e, FileShare.Read) ;

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

I believe the append mode is defined at the "lFile.Open " line with the
correct parameters. Thanks!

Oct 15 '07 #1
1 5802
"Curious" <fi********@yah oo.comwrote in message
news:11******** **************@ k35g2000prh.goo glegroups.com.. .
>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). 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:\\t emp\\debug.txt" );

if (lFile.Exists)
{
// What's the syntax to append new content (instead of
overwriting the existing content?
FileStream lStream =
lFile.Open(File Mode.OpenOrCrea te, FileAccess.Writ e, FileShare.Read) ;

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

I believe the append mode is defined at the "lFile.Open " line with the
correct parameters. Thanks!

The FileInfo class exposes an AppendText method, which you may find useful:

http://msdn2.microsoft.com/en-us/lib...xt(VS.80).aspx

Oct 15 '07 #2

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

Similar topics

1
18897
by: Mark Richards | last post by:
The solutions for the following problems seems to be simple but I did not found a (convenient) solution: Assume we have a number of elements of the same type under a common parent e.g. <person ... myattr="aaa">Paul</person> <person ... myattr="bbb">Peter</person> <person ... myattr="ccc">Karl</person> ..... <person ... myattr="ddd">Stan</person>
1
3242
by: Kevin Potter | last post by:
We have an application that has been running on IIS4 and IIS5 for quite some time, without problem We're now migrating to IIS6 (windows/2003), and have run into a what might? be a Javascipt problem/question... The snippet of code in question is: <script language="JavaScript"><!-- document.write("<script src='/fp/"+includename+"'></script>"); // -->></script>
2
5760
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
0
1308
by: Benny | last post by:
I'm testing to see whether msbuild can replace nmake. project file <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="test"> <Exec Command="test.exe"/> </Target>
7
2708
by: samuelberthelot | last post by:
Hi, I have the following in my asp page: <% response.write(Header) %> where Header contains HTML markup such ass <html> <body> .... I must write the code in the aspx file and not in the code behind so that the markup are generated at correct places in html stream.
2
33906
by: Fred Dag | last post by:
Hi, When writing using both these methods ( StreamWriter.Write("\n") vs WriteLine() ) to a file and open in Notepad I see a special character instead of newlines with Write("\n") vs a newline with WriteLine(). How do I insert characters into a string ( ie "line 1\nline 2\n" ) so that when I write them to Stream they will be interpreted properly as newlines? Thanks in advance
3
2633
by: cc50818j | last post by:
Hi, Can anyone suggest a Unix command or c-shell algorithm to simulate to behavior of "wall" command minus the "all users"? What I'm trying to do is to send a notice to just one particular user but i dont want other remotely-logged-on users to receive the message (on the pseudo-terminals). I cannot use the "write" command for three reasons: 1. I (sender) will not be typing the message from standard input (instead, i will be using a file...
1
5220
by: Hermes | last post by:
Is there a way to write the information that appears in the "Messages" window in SQL Server Management Studio to an external log file? I'd like to keep a record of these logs as I run each script once a month and it would be useful to compare run times for each step. We have several places where we insert variations of the following code along the way which gives us a snapshot of how long a particular step took: SET @Msg = ' - Starting...
2
1485
by: tido | last post by:
Hi, I'm trying to write the following line into a text file: <start>=test this "testthis" the problem is that, when I try to write the ", vb thinks I'm ending the line I want to write... I was using print: Print #iFileNo, "<start>=test this "testthis""
0
8376
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
8290
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
8708
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
7307
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...
0
4149
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
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
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.