Follow by Email

How to write a string in to text file ?


First You have to check whether file exists or not ...if yes then just map the path & write string into file using streamwriter...

if
(File.Exists(Server.MapPath("logfile.txt")))

{
FileStream aFile = new FileStream(Server.MapPath("logfile.txt"),FileMode.Append,FileAccess.Write);
StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine("test to log file.");
sw.Close();

}

0 comments:

Post a Comment