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?