Sunday, August 19, 2012

save text into notepad using c#.net

 public static void SaveMessage(string Message,string FileName)
        {
            string path = HttpContext.Current.Server.MapPath("Messages");
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            string filename = path + "\\" +FileName+"_"+ DateTime.Now.Year.ToString() + DateTime.Now.Month + DateTime.Now.Day + ".txt";
            string error = "\r\nMessage Occur at :" + DateTime.Now.ToString() +
              "\r\nMessage is : \r\n" + Message +          
              "\r\n***********************************************************************************************************************";
            using (StreamWriter strwr = File.AppendText(path))
            {
                strwr.WriteLine(error);
                strwr.Flush();
                strwr.Close();
            }
        }

No comments: