0

Possible Duplicate:
FileSystemWatcher Fails to access network drive

I wrote a service that monitors a folder in a network share (\\\\machinename\abc\) and each time a new file is added, it does something with that file.

The code itself works fine when I run it from a test harness, but when I run it as a service I get a System.IO.FileNotFoundException the moment a new file is added to the network folder, and the service crashes.

The service is running as a User, with my username and password, so I don't know what's going on, especially given that I don't have this problem when I run the code from a test harness from within VS.

******EDIT****** Just wanted to add that I solved the problem. The key is to make sure that the file is readable before attempting to process the file (ie: write a try-catch statement inside a loop and attempt to obtain a FileStream object for the file). Also it's worth noting that for some strange reason this was not an issue when I ran the service from the test harness. Anyway, I'm glad the problem is solved!

Community
  • 1
  • 1
John Smith
  • 4,416
  • 7
  • 41
  • 56
  • 3
    Duplicate: http://stackoverflow.com/questions/8326302/reading-unc-path-with-filesystemwatcher http://stackoverflow.com/questions/11219373/filesystemwatcher-to-watch-unc-path http://stackoverflow.com/questions/960318/filesystemwatcher-fails-to-access-network-drive – Steven Hunt Oct 01 '12 at 18:33
  • 1
    Could you please include your code and an indication of which line causes that exception? – Ashley Ross Oct 01 '12 at 18:36
  • @John, Are you sure the user the service is running under has permission to access the folder? – Jesper Fyhr Knudsen Oct 01 '12 at 18:38
  • 1
    None of the answers to those questions answer my question, so you shouldn't try to get my question deleted. First, the problem is not with the remote server, because this code works fine when it is not run as a Service. Second, the problem is unlikely to be related to permission, because the Service is running with my username/password. – John Smith Oct 01 '12 at 18:40
  • Does your account have "Log On As A Service" privilege? – David W Oct 01 '12 at 18:41
  • David W, I went to "Local Policy" and confirmed that my user name is listed under "Log on as a service". i guess that if I didn't have this privilege then the service wouldn't run at all, don't you think? – John Smith Oct 01 '12 at 18:54

0 Answers0