我使用FileSystemWatcher
來檢測.docx文件。文件在打開時被檢測到,但文件名總是「損壞」。FileSystemWatcher扭曲文件名
3個例子:
如果我的文件名:2711111.docx,在
FileSystemWatcher.Changed
recived文件名是:〜$ 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) {...}
幫助將非常感激:)謝謝!
只有一次變得被觸發?或者打開一個docx文件時多次? – nawfal