using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Windows; using System.Web.Mail; namespace TfL { class Program { static void Main(String[] args) { System.IO.FileInfo info = new System.IO.FileInfo("c:\\Source\\LNS_IS.txt"); if (File.Exists("c:\\Source\\LNS_IS.txt") && (info.Length > 0)) { MailMessage oMsg = new MailMessage(); oMsg.From = "Happy@test.com"; oMsg.To = "246@gmail.com"; oMsg.Subject = "Unattended Mailbox do not reply"; oMsg.BodyFormat = MailFormat.Html; // ADD AN ATTACHMENT. String sFile = @"C:\Source\LNS_IS.TXT"; MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64); oMsg.Attachments.Add(oAttch); //SMTP server. SmtpMail.SmtpServer = "vmtestmac"; SmtpMail.Send(oMsg); oMsg = null; oAttch = null; //move the file now email is sent string sourceFile = @"C:\Source\LNS_IS.txt"; string destinationFile = @"C:\Archive\LNS_IS.txt"; System.IO.File.Move(sourceFile, destinationFile); //shows message for testing global::System.Windows.Forms.MessageBox.Show("sending File Exists "); } else { MailMessage oMsg = new MailMessage(); oMsg.From = "Happy@test.com"; oMsg.To = "246@gmail.com"; oMsg.Subject = "Unattended Mailbox do not reply"; oMsg.BodyFormat = MailFormat.Html; //SMTP server. SmtpMail.SmtpServer = "vmtestmac"; SmtpMail.Send(oMsg); oMsg = null; //shows message for testing global::System.Windows.Forms.MessageBox.Show("sending file not exist"); } //checking if file has any data if (info.Length < 1) { //move the file string sourceFile = @"C:\Source\LNS_IS.txt"; string destinationFile = @"C:\Baddata\LNS_IS.txt"; System.IO.File.Move(sourceFile, destinationFile); } } } }
DirectoryInfo dirInfo = new DirectoryInfo(@"c:\MyDir"); string[] files = dirInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly);
string[] files = System.IO.Directory.GetFiles(@"c:\MyDir", "*.txt", SearchOption.TopDirectoryOnly);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)