dus*_*usm 4 .net c# filesystemwatcher
我正在使用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) {...}
Run Code Online (Sandbox Code Playgroud)
将非常感谢帮助:)谢谢!
这是为Microsoft Word设计的.它在用户打开文档时创建隐藏文件.该文件记录用户名,以便当其他人尝试打开同一文档时,他们将获得一个体面的消息,告诉他们当前用户打开了哪些文档进行编辑.
该隐藏文件的文件名是原始文件名,前两个字符替换为 ~$
使用资源管理器查看目录时,通常不会看到此文件,因为它已打开FileAttributes.Hidden属性.当然,您也想忽略这些文件,使用FileInfo.Attributes属性来过滤它们.
| 归档时间: |
|
| 查看次数: |
1437 次 |
| 最近记录: |