Exemplo n.º 1
0
 public static bool writeToFile(string filePathAndName, string[] dataResult)
 {
     try
     {
         if (Directory.Exists(Path.GetDirectoryName(filePathAndName)) == false)
         {
             Directory.CreateDirectory(Path.GetDirectoryName(filePathAndName));
         }
         using (var fs = new FileStream(filePathAndName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
         {
             using (var fw = new StreamWriter(fs))
             {
                 foreach (string row in dataResult)
                 {
                     fw.WriteLine(row);
                 }
             }
         }
     }
     catch (IOException ie)
     {
         Mailer.MailContent mc = new Mailer.MailContent();
         // make mail content
         mc.Subject = "[Error] write the message error";
         mc.Body    = ie.Message;
         Mailer.sendMail(mc);
     }
     return(true);
 }
Exemplo n.º 2
0
        public static bool writeDataTableToFile(string filePathAndName, DataTable dt, bool includeHead)
        {
            try
            {
                if (Directory.Exists(Path.GetDirectoryName(filePathAndName)) == false)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filePathAndName));
                }
                using (var fs = new FileStream(filePathAndName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    using (var fw = new StreamWriter(fs))
                    {
                        if (includeHead == true)
                        {
                            foreach (DataColumn col in dt.Columns)
                            {
                                fw.Write(col.ToString() + "\t");
                            }
                            fw.WriteLine();
                        }

                        foreach (DataRow row in dt.Rows)
                        {
                            foreach (object item in row.ItemArray)
                            {
                                fw.Write((string)item + "\t");
                            }
                            fw.WriteLine();
                        }
                    }
                }
            }
            catch (IOException ie)
            {
                Mailer.MailContent mc = new Mailer.MailContent();
                // make mail content
                mc.Subject = "[Error] write the message error";
                mc.Body    = ie.Message;
                Mailer.sendMail(mc);
            }

            return(true);
        }
Exemplo n.º 3
0
 public static void writeErrorMessage(string message)
 {
     try
     {
         using (var fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/errormessage.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
         {
             using (var fw = new StreamWriter(fs))
             {
                 fw.Write(message);
                 fw.Flush();
             }
         }
     }
     catch (IOException ie)
     {
         Mailer.MailContent mc = new Mailer.MailContent();
         // make mail content
         mc.Subject = "[Error] write the message error";
         mc.Body    = ie.Message;
         Mailer.sendMail(mc);
     }
 }