简体   繁体   中英

Determine the last user who modified the file on mapped network drive?

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!

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.
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM