Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am creating a windows form in vb.net.. and in this i want to write a text file and after writing i have to save that file...plz help me
Posted

 
Share this answer
 
Comments
shashank 1068 6-May-13 1:42am    
i want to write and save a text file under single button
shashank 1068 6-May-13 1:45am    
so how to write and save a file under single button??
or should i write the WRITE code and SAVE code under single button???
Maciej Los 6-May-13 1:46am    
Please, follow the lniks. There you'll find examples.
shashank 1068 6-May-13 1:48am    
kkk thnx :)
C#
using System;
using System.Collections.Generic;
using System.Text;

using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string sData = "Hello Developer !";

            //ANSWER 1:
            using (FileStream fStream = File.Open(@"D:\MyFile.txt", FileMode.OpenOrCreate))
            {
                byte[] bt = Encoding.ASCII.GetBytes(sData);
                fStream.Write(bt, 0, bt.Length);

                fStream.Close();
            }

            //ANSWER 2 [Append In Existing Data]:
            File.AppendAllText(@"D:\MyFile.txt", sData);

            //ANSWER 3 [Fulsh Current Data An Write New One]:
            File.WriteAllText(@"D:\MyFile.txt", sData);
        }
    }
}
 
Share this answer
 

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