我FileSystemWatcher
用来检测.docx文件。打开时会检测到文件,但文件名总是“损坏”。
3个例子:
如果我的文件名是:2711111.docx,则接收的文件名
FileSystemWatcher.Changed
是:~$711111.docx。对于文件:*2711111_1.docx* 我得到文件名:*~$11111_1.docx* 我猜不出我的文件名是什么,所以我正在寻找一个通用的解决方案。
对于文件包含/以字母开头,它不会发生。
这是我的代码
MyPath = String.Format(@"C:\Users\{0}\NRPortbl\ACTIVE\{1}\"",
Public.UserName, Public.UserName);
FileSystemWatcher watcher = new FileSystemWatcher();
if (!System.IO.Directory.Exists(MyPath))
{
Public.Logger.Error(
String.Format
("Path of folders {0} not found", MyPath));
System.Windows.Forms.MessageBox.Show(
String.Format(
"There was a problem loading {0} " +
"NRPortbl libraray, contact administrator", Public.UserName));
return;
}
watcher.Path = MyPath;
watcher.Filter = "*.Docx";
watcher.IncludeSubdirectories = false;
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnDeleted);
watcher.EnableRaisingEvents = true; ...
public void OnChanged(object source, FileSystemEventArgs e) {...}
帮助将不胜感激:) 谢谢!