【问题标题】:Path property of FileSystemWatcherFileSystemWatcher 的路径属性
【发布时间】:2015-02-18 20:43:14
【问题描述】:

我正在制作一个应用程序,在该应用程序中我使用 OpenFileDialog 打开一个 txt 文件。

一切都很好,我阅读和处理信息。

现在我想使用 FileSystemWatcher 来监视文件的任何可能更改。

当我尝试将文件路径分配给对象时,我得到一个异常:

...

 public string PathOpenFile = null; 

...

 PathOpenFile = openFileDialog1.FileName;

 MyFileSystemWatcher.Path = PathOpenFile;

出现的消息说: "目录名 C:\Users\fromo\Desktop\DATA-TRAMA(192.168.1.5_PinPad_UNO)test2.txt 不是无效的"

有什么想法或建议吗?

谢谢

【问题讨论】:

  • "目录名 xxx不在有效" ?!
  • 使用 FolderBrowserDialog 选择目录。

标签: c# path filesystemwatcher


【解决方案1】:

我很抱歉我的错误(不是无效的”),正确的是“无效”

我的问题的解决方法是:

PathOpenFile = openFileDialog1.FileName;

MyFileSystemWatcher.Path = System.IO.Path.GetDirectoryName(PathOpenFile);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 2019-12-11
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    相关资源
    最近更新 更多