Click here to Skip to main content
Rate this: bad
good
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
555336631
Edited 5-May-11 14:09pm
v2
Comments
Ankit Rajput at 2-May-11 6:43am
   
have you tried this code without making the file?
charles henington at 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 at 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
good
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:
http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx[^] (you can search for "Append" to see this place).
 
—SA
  Permalink  
Comments
bunnyali2011 at 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 at 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.
--SA
bunnyali2011 at 2-May-11 14:32pm
   
@SAKryukov, I got the answer...Append in streamwriter does create
SAKryukov at 2-May-11 14:56pm
   
Great,
Now, are you going to formally accept this answer (green button)?
Thank you.
--SA
Rate this: bad
good
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.
  Permalink  
Comments
bunnyali2011 at 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 at 2-May-11 6:48am
   
I'm new in VB.net that's why I want a confirmation if Append also creates..as 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 at 2-May-11 6:48am
   
so which type of opinion you want?
bunnyali2011 at 2-May-11 7:17am
   
Does Append ONLY also create?
SAKryukov at 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.
--SA

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

  Print Answers RSS
0 OriginalGriff 495
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 200
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 5 May 2011
Copyright © CodeProject, 1999-2014
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