【问题标题】:Determine the last user who modified the file on mapped network drive?确定最后修改映射网络驱动器上文件的用户?
【发布时间】:2015-01-23 04:32:31
【问题描述】:

我有一个关于映射网络驱动器的问题。

我有 3 台电脑:A、B 和 C。每台电脑都有一个映射的网络驱动器是 Share2All(\Server)Z:,这个驱动器指向服务器上的一个公共文件夹,是 >Share2All 文件夹。

我有一个应用程序,它使用 FileSystemWatcher 来监视 PC 上的文件。此应用程序在 3 台 PC 上运行:A、B 和 C。

在 PC 上,当我编辑并保存具有路径的文件时:Z:\test.txt(在映射的网络驱动器上),更改的事件(FileSystemWatcher) 出现在同一个 A、B 和 C PC 上。

我希望,当我在 PC 上编辑和保存文件 Z:\test.txt 时,更改的事件只出现在 PC 上。

为此,我尝试确定最后修改文件 Z:\test.txt 的用户(是 PC 上的用户),但它不可能。

谁能帮我确定上次修改映射网络驱动器上文件的用户,或者为我的问题提供任何解决方案?

谢谢!

【问题讨论】:

标签: c# filesystemwatcher last-modified mapped-drive


【解决方案1】:

我没有尝试过这个,但它应该适合你, 从 FileSystemWatcher 创建一个扩展类并为其分配一个 Tag 值。

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

    }

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

    }

    public object Tag
    {
        get;
        set;
    }

}

你可以这样称呼它,

        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;

在改变的事件中,

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

    }

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多