Home » excel » winforms – Using C# how do you determine if an excel file located on server has been updated. This check needs to be performed every 24 hrs

winforms – Using C# how do you determine if an excel file located on server has been updated. This check needs to be performed every 24 hrs

Posted by: admin May 14, 2020 Leave a comment

Questions:

So far I have tried this code which shows for 1 file last update.

        FileInfo fileInfo = new FileInfo(@"C:\Users\Desktop\test.xlsx");
        DateTime lastWriteTime = fileInfo.LastWriteTime;
        Console.WriteLine(lastWriteTime);
        MessageBox.Show("test" + lastWriteTime);

I want to know how this could be automatically ran every 24 hrs as I need to perform a check on various files of more than 1 folder based on the file system.

How to make it a windows service which runs in background.

How to&Answers:

One potential solution here is to create a Windows service as mentioned. TopShelf is an open source project that can help you quickly create Windows services that are easy to install and uninstall. The documentation is a little sparse but it’s relatively easy to use the example to get up and running. Tangentially, I’d also like to give you some advice about the FileSystemWatcher that I’ve learned through experience: You’ll want to “watch” for a minute or two at a time, or some interval that’s reasonable, then recreate the watcher again. If the underlying file system falls out from under the FileSystemWatcher, it won’t know. This can make it seem like the FileSystemWatcher “doesn’t work”.