Click here to Skip to main content
11,920,394 members (57,108 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET stream
Ok, I'm asking again this question, does Append in StreamWriter also can create a text file if the latter does not exist?

Here is my code below:

Posted 2-May-11 1:36am
Edited 5-May-11 14:09pm
Ankit Rajput 2-May-11 6:43am
have you tried this code without making the file?
charles henington 2-May-11 8:38am
do MessageBox.Show(filename) inspect the file name to ensure that it is correct. You may be missing an \ between the last directory and filename.
bunnyali2011 2-May-11 10:40am
No, I have declared my filename. my text file is in the debug folder, so I put:

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The solution exist: you first create an instance of System.IO.FileStream and then create a System.IO.StreamWriter based on that stream.

The complete code sample is shown here:[^] (you can search for "Append" to see this place).

bunnyali2011 2-May-11 10:37am
I did read this article, I posted this because some people are not believing me that only Append can create a file if it does not exist. It is not necessary to add a Boolean of Create filestream. I just need a confirmation of 'Yes' or 'No' from you that's all. Because on my PC it does create the text file even it does not exist.
SAKryukov 2-May-11 14:28pm
I don't understand. If "on your PC" something is not created, there is a reason, like user permissions, that's all. This topic is not a matter of experiments; everything should be explained. Now, if you have a appending solution without creations of the stream, I want to see it. StreamWriter does not have append mode indeed. So, please explain.
bunnyali2011 2-May-11 14:32pm
@SAKryukov, I got the answer...Append in streamwriter does create
SAKryukov 2-May-11 14:56pm
Now, are you going to formally accept this answer (green button)?
Thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In general scenerio, StreamWriter will create new file if it doesn't exist when it is in append mode.
bunnyali2011 2-May-11 6:45am
Of course man, and believe me, it creates the text file if it does not exist even I used Append. I'm posting this to confirm from you all as I want all opinions.
bunnyali2011 2-May-11 6:48am
I'm new in that's why I want a confirmation if Append also many are saying only Create which creates file not Append. Even I have read many articles, they did not mention that Append also creates.
Ankit Rajput 2-May-11 6:48am
so which type of opinion you want?
bunnyali2011 2-May-11 7:17am
Does Append ONLY also create?
SAKryukov 2-May-11 8:59am
Ok, Ankit, if you think this is so in "general" scenario, what do your think of other scenarios?

Well, the solution exist and is very simple, you will find a code sample;
Please see my solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 5 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100