0

Possible Duplicate:
FileSystemWatcher Fails to access network drive

My service uses System.IO.Directory.Exists(pathFetch) to check if the path is valid. If I run this statement, it returns true. If this condition is true, I can continue with the next code.

Now that I know that the Directory exists, I want to use the FileSystemWatcher class to monitor any changes in the folder.

String pathFetch = "\\\\computer1\\sharedfolder\";

FileSystemWatcher fsw = new FileSystemWatcher();
fsw.path = pathFetch;
fsw.filter = "*.xml";
fsw.EnableRaisingEvents = true;
fsw.Created += new FileSystemEventHandler(onCreatedFile);

If I use this code with a local folder, the statement returns true, and there isn't any FileEventHandler errors. But with the UNC path in the previous exemple, I get the following:

Service cannot be started. System.IO.FileNotFoundException: Error reading the \\\\computer1\\sharedfolder\ directory.
    at System.IO.FileSystemWatcher.StartRaisingEvents()
    at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
    at Epgpubpooler.epgmaintainer.initFileWatcher(String pathFetch)
    at Epgpubpooler.epgmaintainer.OnStart(String[] args)
    at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

EDIT:

If I add a try catch, and I print the ex.Message I get: Error reading the \\\\computer1\\sharedfolder\ directory.

How can I solve this problem?

Community
  • 1
  • 1
guiomie
  • 4,728
  • 6
  • 36
  • 67
  • Have you tried without the trailing backslash in pathFetch? – Anders Marzi Tornblad Nov 30 '11 at 13:03
  • Also, is the target system Windows NT-based? The FileSystemWatcher only works on NTFS file systems. – Anders Marzi Tornblad Nov 30 '11 at 13:04
  • More also: What user account are you running your service under? Does that user account have the required permissions in the share that you are trying to watch? – Anders Marzi Tornblad Nov 30 '11 at 13:07
  • I have tried without the trailing backslash, it is a windows server 2003 os, the disk is NTFS, and I am running the service under the same account as I use when I log on the server (administrator). If I copy and paste the UNC path in the file explorer it works no problem. the folders sharing parameters are set to "everyone" – guiomie Nov 30 '11 at 13:13
  • If I use the Local System Account System.IO.Directory.Exists() returns false. So my guess it that I have the proper privileges to see if it exists, but not to use the filesystemwatcher (?)? – guiomie Nov 30 '11 at 13:16
  • Are you trying this from a Windows Server ? – Yahia Nov 30 '11 at 14:42
  • Yes. To another windows server – guiomie Nov 30 '11 at 15:20

0 Answers0