1

I have an issue about mapped network drive.

I have 3 PCs: A, B and C. Each PC have a mapped network drive is Share2All(\Server)Z:, this drive point to a common folder on server, is Share2All folder.

I have an application which using FileSystemWatcher to monitor files on PC. This application is running on 3 PCs: A, B and C.

On A PC, when I edit and save a file which has path: Z:\test.txt (on mapped network drive), the changed event (of FileSystemWatcher) appear at same A, B and C PC.

I want, when I edit and save file Z:\test.txt on A PC, the changed event only appear on A PC.

To do this, I try to determine the last user who modified the file Z:\test.txt (is user on A PC), but it could not be.

Can anyone help me determine the last user who modified the file on mapped network drive, or give me any solution for my issue?

Thanks!

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Nho Le
  • 44
  • 6
  • http://stackoverflow.com/questions/11660235/find-out-usernamewho-modified-file-in-c-sharp – artm Jan 23 '15 at 04:53
  • Be aware that `FileSystemWatcher` may miss events under high load so it's a good idea to periodically poll. [Tell me more](http://stackoverflow.com/questions/239988/filesystemwatcher-vs-polling-to-watch-for-file-changes) –  Jan 23 '15 at 04:57

1 Answers1

0

I haven't tried with this one, but It should work for you, Create an extended class from FileSystemWatcher and assign a Tag value it.

public class ExFileWatcher : FileSystemWatcher
{
    public ExFileWatcher(string filePath)
        : base(filePath)
    {

    }

    public ExFileWatcher(string filePath, string filter)
        : base(filePath,filter)
    {

    }

    public object Tag
    {
        get;
        set;
    }

}

and you can call it like,

        ExFileWatcher fw = new ExFileWatcher("DirectectoryPath", "*.txt");
        fw.Changed += fw_Changed;
        //Assign a tag here differently on different machine.
        fw.Tag = "1st machine";
        fw.EnableRaisingEvents = true;

and in the changed event,

void fw_Changed(object sender, FileSystemEventArgs e)
    {
        if ((sender as ExFileWatcher).Tag == "1st machine")
        {
            //This is first machine.
        }
        else if ((sender as ExFileWatcher).Tag == "2nd machine")
        {
            //This is Second machine.
        }

    }
Rohit Prakash
  • 1,975
  • 1
  • 14
  • 24