如题。
当本机的某个文件夹中的的新增的文件时,系统会自动将此新增的文件复制到本地局域网的另一台机器上?

解决方案 »

  1.   

    FileSystemWatcher 类
    命名空间: System.IO
    侦听文件系统更改通知,并在目录或目录中的文件发生更改时引发事件。
      

  2.   

    参考本地的
    ms-help://MS.NETFrameworkSDKv1.1.CHS/cpref/html/frlrfsystemiofilesystemwatcherclasstopic.htmorhttp://msdn.microsoft.com/library/CHS/cpref/html/frlrfSystemIOFileSystemWatcherClassTopic.asp
      

  3.   

    File/Folder Watcher Wrapper
    http://www.codeproject.com/csharp/FileWatcherWrapper.aspMonitor all file system activity on a target server
    http://www.codeproject.com/csharp/Monitor_All_Filesystem.asp
      

  4.   

    我按以下思路做,但还是有一些问题:
    1、在FileSystemWatcher 组件的Created事件里面写代码,因为我只要求将此文件夹内新增的文件复制到局域网另一台机子内。2、思路是:先将目的机器的磁盘映射到本地机器上,然后将文件复制到此映射盘中,最后删除映射盘。针对以上思路的代码如下://调用创建映射盘的批处理文件,以创建映射名
    Process.Start("D:\\shishiWeb\\WebManage\\CopyAttachment\\CreateDrive.bat");//取到新增的文件名
    strFilePath = e.FullPath;
    strFilaName = e.Name;try
    {
             //复制文件
    System.IO.File.Copy(strFilePath,"P:\\shishiWeb\\Attachment\\Hotsubject\\" + strFilaName,true);
    }
    catch
    {

    }
    finally
    {
    //调用删除映射盘的批处理文件,以删除映射盘
    Process.Start("D:\\shishiWeb\\WebManage\\CopyAttachment\\DeleteDrive.bat");
    }但这样也存在以下问题:
    1、是否需要显式地关闭线程?何时关闭?
    2、由于用户对所监测的文件夹操作过于频繁,导致了常常一次工作(建立映射盘、复制文件、删除映射盘)还没有完成,但又开始了另一个动作,这时两个动作均创建同样盘符的映射盘而出错。不知有什么好的解决方案可以解决这个问题。