I have developed a Windows service application. All this service does is initiate filewatcher and listen for a .csv file being created, then it processes that file. Before now we were using the application folder for monitoring, but as security permissions are required to copy the file inside the application root directory we decided to change its path to be the My Documents folder. After the installer completes during the installation process, the ProductName folder is created under the My Documents folder. (The archive folder is also created under ProductName folder.) After the install we have a structure like My Documents\ProductName\Archive\
When we try to start the service, it stops, and the only exception we could see inside event viewer is:
Exception Info: System.ArgumentException Stack: at System.IO.FileSystemWatcher.set_Path(System.String)
public partial class ServiceName : ServiceBase
{
private readonly IMachineResultProcessos _controler;
private readonly FileSystemWatcher _watcher;
private readonly string _rootpath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments),"ProductName");
public ServiceName()
{
InitializeComponent();
_controler = new DataProcessos();
_watcher = new FileSystemWatcher
{
Path = _rootpath + @"\Archive",
Filter = "*.csv"
};
_watcher.Created += OnFileCreated;
_watcher.EnableRaisingEvents = true;
}
}
It works under debug, but has problems when deploying on client machine.
Any suggestions or ideas would be welcome.