Wednesday, 10 September 2014

Create text file using C#




string folderName = AppDomain.CurrentDomain.BaseDirectory + @"Log";
 if (!Directory.Exists(folderName))
 {
    Directory.CreateDirectory(folderName);
 }

 String fileName = folderName + "\\TraceLog " + DateTime.Now.ToString("MMddyyyyHHmmss") + ".txt";
 if (!File.Exists(fileName))
 {
     using (StreamWriter sw = File.CreateText(fileName))
     {
            sw.Write(Message);
            sw.Close();
     }

 }

No comments:

Post a Comment