Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

Writing to a text file in c#

The .NET Framework includes convenience classes that make reading and writing text files very easy this small article shows you how to create and write to a text file

The code when executed creates a text file called tx.txt in the current working directory.

The WriteLine method allows us to write to the text file

Once we write the text we have to close the file using the tw.close method


using System.IO;


static void Main()
{
// create the writer and open the file
TextWriter tw = new StreamWriter("t.txt");

// write a line of text to the file
tw.WriteLine("Hello world!");

// close the stream
tw.Close();
}




Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy