Click here to Skip to main content
15,918,268 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Bernhard Hiller 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)?
Joshi, Rushikesh 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)

sjelen 11-May-12 10:12am    
Have you checked permissions on UNC path? Are you working on domain or workgroup network?

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.
Share this answer
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:

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:
This solution worked for me.
Share this answer
Bernhard Hiller 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 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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900