The following articles discusses, how one can read and write into a text file using ASP.net Firstly you will need to import using System.IO; .
1. Writing to a Text File
using System;
using System;
using System.IO;
namespace yasser.howto
{
class TextFileWriter
{
static void Main(string[] args)
{
// create a writer and open the file
TextWriter tw = new StreamWriter(“yrus.txt”);
// write a line of text to the file
tw.WriteLine("Line to be written in the file!");
// close the stream
tw.Close();
}//end of method
}//end ofclass
}
_________________________________________________________________
2.Reading From a Text File
using System;
using System.IO;
namespace yasser.howto
{
class TextFileReader
{
static void Main(string[] args)
{
// create reader & open file
StreamReader sr = new StreamReader(“yrus.txt”);
// read a line of text
Console.WriteLine(sr.ReadLine());
// close the stream
sr.Close();
}
}
}
-keep coding !
0 comments:
Post a Comment