.NET 的删除文件事件
我想在删除文件之前获取一个事件?
我该怎么做呢?
I want to get an event Before a file is being deleted?
How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想在删除文件之前获取一个事件?
我该怎么做呢?
I want to get an event Before a file is being deleted?
How can I do it?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
根据我对这个问题的回答:如何阻止使用 Windows 服务创建文件夹?
System.IO.FileSystemWatcher 或 .net Framework 中的任何其他内容均不支持(就目前而言)我知道)在文件被删除之前接收事件,即在删除请求到达文件系统时,但在它被执行之前(我在这里假设您希望能够有选择地取消请求删除文件)。
如果您想走这条路,您需要做的是编写 文件系统过滤器驱动程序,据我所知,您必须用非托管代码编写它。
As per my answer to this question: How could I prevent a folder from being created using a windows service?
There's no support within the System.IO.FileSystemWatcher, or anything else within the .net Framework (as far as I'm aware) for receiving an event prior to a file being deleted, i.e. at the point the deletion request hits the file system, but prior to it being actioned (I'm assuming here that you want to be able to selectively cancel requests to delete files).
What you'll need to do, if you want to go down this route, is write a File System Filter Driver, which you'll have to write in unmanaged code as far as I'm aware.