?
Solved

File watcher works on one server UNC path but not for another

Posted on 2014-04-15
3
Medium Priority
?
382 Views
Last Modified: 2015-06-15
I have a windows service that is a setup as a File watcher service. I use the following class to setup my watchers:
    public class Watcher
    {
        FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();

        public string Directory { get; set; }
        public string Filter { get; set; }

        private Delegate _changeMethod;

        public Delegate ChangeMethod
        {
            get { return _changeMethod; }
            set { _changeMethod = value; }
        }
        public Watcher(string directory, string filter, Delegate invokeMethod)
        {
            this._changeMethod = invokeMethod;
            this.Directory = directory;
            this.Filter = Filter;
            fileSystemWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Attributes | NotifyFilters.CreationTime
           | NotifyFilters.Security | NotifyFilters.Size;
        }
        public void StartWatch()
        {
            fileSystemWatcher.Filter = this.Filter;
            fileSystemWatcher.Path = this.Directory;
            //fileSystemWatcher.Changed += new FileSystemEventHandler(fileSystemWatcher_Changed);
            fileSystemWatcher.Created += new FileSystemEventHandler(fileSystemWatcher_Changed);
            fileSystemWatcher.EnableRaisingEvents = true;
        }
        void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (_changeMethod != null)
            {
                _changeMethod.DynamicInvoke(sender, e);
            }
        }
    }

Open in new window


I invoke it using the following code:
                Watcher[] w1 = new Watcher[tradingDataSet.tblSpecNewAcct.Rows.Count+1];
                
                for (int i = 0; tradingDataSet.tblSpecNewAcct.Rows.Count - 1 >= i; i++)
                {
                    w1[i] = new Watcher(tradingDataSet.tblSpecNewAcct.Rows[i]["ImportLocation"].ToString(), "*.*", mymethod);
                    EventLog.WriteEntry("New Watcher " + tradingDataSet.tblSpecNewAcct.Rows[i]["ImportLocation"].ToString());
                    w1[i].StartWatch();
                    EventLog.WriteEntry("Watcher started for " + tradingDataSet.tblSpecNewAcct.Rows[i]["ImportLocation"].ToString());
                }

Open in new window


The paths that are retrieved from the database are in the format of :

\\server\folder1\folder2

Open in new window


The service works for our test server but when I switch to the production UNC paths it produces the following error:

The directory name \\server\folder1\folder2 is invalid.

Open in new window


Could this be a permissions problem? The services user credentials is "Network Service" and we have added full permissions for it to the production Folder.

What would make it work on one server path and not for another?
0
Comment
Question by:ButtonDownBobby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:ButtonDownBobby
ID: 40001841
I tried putting the code into a windows application and it works with the production server but the service still doesn't work. I guess my credentials are valid for the windows form but the service does not seem to be able to access the UNC path.
0
 

Author Comment

by:ButtonDownBobby
ID: 40002042
I just changed the "Logon" for the service to use my logon account credentials and the service can access the production UNC path.  This leads me to believe that I have to do something on the production server's user rights for "NETWORK SERVICE". What do I have to do...?
0
 
LVL 27

Accepted Solution

by:
skullnobrains earned 1500 total points
ID: 40006646
you probably won't be able with that (very limited) account

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684272%28v=vs.85%29.aspx

you can create a dedicated account with the needed rights and run the service under that account
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question