I'm looking for a way to programmatically detect the arrival of a file in a shared folder. So far, the best I have is some kind of Windows service that contains a FileSystemWatcher; that service, in turn, either fires off an SPTimerJob, etc. (the end goal is to run code that updates a list and writes several xml files). The file is deposited in the folder by an automated service.

If you know of any way of doing this, please let me know.

TIA Josh


Rather than relying on an external service agent to monitor these changes and then interact with SharePoint why not use a SharePoint timer job?

With a SharePoint timer job you are using a key piece of the SharePoint platform which supports periodic execution of tasks. You could simply create a solution that deploys a timer job to monitor a fileshare for change using simple .Net functionality to examine files newer than the time the job last ran.

For example;

using System.IO; 

string[] files = Directory.GetFiles(dirName);

foreach (string file in files)
   FileInfo fi = new FileInfo(file);
   if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))

This way you can monitor the job directly from SharePoint central admin. You can also log to the ULS or against the job and view the results. Finally, everything would run as your service account for SharePoint and restart / resume during farm reboots etc without any maintenance of external programs such as your proposed agent.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.