无法使用FileSystemWatcher检测对Microsoft文档的更改 [英] Unable detect changes to Microsoft documents using filesystemwatcher
问题描述
我已经在互联网上进行了很多研究,但无法解决此问题.
I have researched quite a bit on the internet but unable to get a solution to this issue.
这是我的代码:
m_Watcher.Filter = "*.*";
m_Watcher.Path = settings.FolderName;
m_Watcher.IncludeSubdirectories = true;
m_Watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
m_Watcher.Created += new FileSystemEventHandler(OnCreated);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;
每当我对word或excel文件进行更改时,都会生成太多临时文件所有这些都是隐藏的,到目前为止,我仅设法忽略了这些
临时文件和隐藏文件在执行时且无法检测对实际文件所做的更改.我该怎么办?
Whenever I make changes to a word or excel file too many temporary files get generated all of which are hidden and so far I have only managed to ignore these
temp and hidden files at execution time and unable to detect the changes made to the actual file. How may I do this?
推荐答案
您好Mainak009,
Hi Mainak009,
谢谢您在这里发布.
对于您的问题,也许您可以执行以下代码.
For your question, maybe you could do the following code.
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
For more details, you could refer to the MSDN article FileSystemWatcher.NotifyFilter.
Based on my search, you could download sourcefile from C#: Application to Watch a File or Directory using FileSystem Watcher. I tried it. It works well.
我希望这会对您有所帮助.
I hope this would be helpful to you.
如果还有其他问题,请随时与我们联系.
If you have something else, please feel free to contact us.
最好的问候,
温迪
这篇关于无法使用FileSystemWatcher检测对Microsoft文档的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!