Hello All,
I am working on developing a tool using C#.net to monitor a a shared file
continuously. It has to generate an e-mail whenever there is any
modification in the shared file. Initially I tried using FileSystemWatcher
class. But it is triggers multiple events at once,thus generating multiple
e-mails. So, I tried with polling together with FileInfo class. It is
working fine except that it is generating an additional email giving the
modification time as: "1601-01-01,05:30:00.00".Even debugging with
breakpoints is not working out as in that case this problem is not
encountered. My code is:
static void Main(string[] args)
{
string data;
string lastwrite;
for(;;)
{
//Read LastWriteTime of the monitored file stored in a
.txt file.
using (StreamReader reader = new
StreamReader(@"d:\fileinfo.txt"))
{
data = reader.ReadToEnd();
}
//File to be monitored
string MyFile = @".xlsx";
FileInfo fInfo = new FileInfo(MyFile);
string lstWrite =
fInfo.LastWriteTime.ToString("yyyy-MM-dd,HH:mm:ss.ff");
lastwrite = lstWrite.ToString();
if (data != lastwrite)
{
System.IO.File.WriteAllText(@"d:\fileSize.txt",
lstWrite);
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp server
name");
mail.From = new MailAddress("");
mail.To.Add("");
mail.Subject = "Modification";
mail.Body = "File has been Modified at : " + lstWrite;
if (lstWrite != "1601-01-01,05:30:00.00")
{
SmtpServer.EnableSsl = true;
try
{
SmtpServer.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
}
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net