Solved

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

Posted on 2014-04-15
3
258 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
  • 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 26

Accepted Solution

by:
skullnobrains earned 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now