Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#Services
I have a service that implements FileSystemWatcher to watch for changes to one file on a remote computer. I use a UNC path for the path to the file but, I get an error in the event log saying that the path is invalid. I confirmed that the path is actually valid. Also, in the service I tried ALL the different account types with a valid username and password. I also confirmed that my code is correct as I tested it successfully using a local path in the FileSystemWatcher. So, what am I missing? I read on other sites how some have successfully used UNC paths to monitor files on remote computers using FileSystemWatcher but, they didn't provide any real insight on how it was accomplished.
 
Any practical suggestions on how this is done would be greatly appreciated.
Posted 11-May-12 3:16am
Comments
Bernhard Hiller at 11-May-12 9:42am
   
Strange. Did you run the service with exactly that user account with which you determined that the path is valid? And - might look like a stupid question, but my experience tells me to ask - does your UNC path start with something like \\servername\share or with a mapped drive letter (X:\somefolder)?
rushijoshi at 11-May-12 9:49am
   
Please provide code where you are calling folder for FileWatcher services, also provide path you are trying. (Dont worry will not open, just to check extra characters) Thanks Rushi
sjelen at 11-May-12 10:12am
   
Have you checked permissions on UNC path? Are you working on domain or workgroup network?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

A UNC path may be valid BUT is needs to be valid for the account trying to access it, also a UNC path may become unavailable for a short period which causes the FileSystemWatcher to report an invalid path.
 
So with this in mind;
1. the account you test the UNC path with, is this the same as used by the service? If not it must be otherwise the account you are testing with may not have the same permissions to access network resources as the account the service runs under.
 
2. When a UNC path becomes unavailable for wahtever reason you need to catch the error and retry at a later date, an article that can show how to do this is FileSystemWatcher - Pure Chaos (Part 1 of 2)[^]
 
Remember when using a UNC path it may or may not be valid and you really need to know why this may be, either due to account permissions or the server going down.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thanks for all the replies and the proposed solution.
 
I found that I needed to share the exact folder that the service was attempting to access instead of simply adding the user account to the server and using a full unc path.
 
In other words, here is what I was doing at first:
1.) Add the user account to the server
2.) Use the FULL unc path in the filewatcher:
\\servername\drive_share\folder1\folder2\TARGET_Folder\
THIS DID NOT WORK.
 
Note: TARGET_Folder is the folder that the service needs to access
on a Windows2008 server.
 
The solution that worked for me is as follows:
1.) Add the user account to the server
2.) Share the exact folder (TARGET_Folder) the service needs to access
3.)Use the unc path directly to the shared folder in the filewatcher:
\\servername\TARGET_Folder
This solution worked for me.
  Permalink  
Comments
Bernhard Hiller at 14-May-12 1:45am
   
"drive_share"? Do you mean \\myserver\c$\folder1 ...? That's hardly feasible, typically only administrators can access drives remotely.
Chad Ehret at 21-May-12 17:07pm
   
When you say "Add the user account to the server", are you talking about the server on which the service is being hosted/run, or are you talking about the server with the folder to be watched?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 412
1 sanket saxena 355
2 Abhinav S 258
3 OriginalGriff 235
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,704
1 OriginalGriff 5,000
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 11 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid