Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Updated 5-May-11 13:09pm
v2
Comments
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.
555336 2-May-11 10:40am    
No, I have declared my filename. my text file is in the debug folder, so I put:


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
 
Share this answer
 
Comments
555336 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.
Sergey Alexandrovich Kryukov 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
555336 2-May-11 14:32pm    
@SAKryukov, I got the answer...Append in streamwriter does create
Sergey Alexandrovich Kryukov 2-May-11 14:56pm    
Great,
Now, are you going to formally accept this answer (green button)?
Thank you.
--SA
In general scenerio, StreamWriter will create new file if it doesn't exist when it is in append mode.
 
Share this answer
 
Comments
555336 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.
555336 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 2-May-11 6:48am    
so which type of opinion you want?
555336 2-May-11 7:17am    
Does Append ONLY also create?
Sergey Alexandrovich Kryukov 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900