1

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.

Jay Sullivan
  • 17,332
  • 11
  • 62
  • 86
Rati_Ge
  • 1,262
  • 2
  • 15
  • 37
  • Which user account is the service running under? Does that account have a My Documents? – Jason Jun 13 '12 at 21:38
  • Have you validated that you have access to the path and that it exists? – Bryan Crosby Jun 13 '12 at 21:38
  • Have you checked which account your service is running under? The account may not actually have "My Documents", whereas during debugging you will be running as yourself. – Duncan Howe Jun 13 '12 at 21:38
  • Service is running under Local System Account after installation. I Have verified that path exists as it is created during installation process (we are using Advanced Installer) – Rati_Ge Jun 13 '12 at 21:39

0 Answers0