如何拦截访问文件在.NET程序 [英] How to intercept the access to a file in a .NET Program

查看:124
本文介绍了如何拦截访问文件在.NET程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要拦截在系统尝试访问到一个文件,并做一些事情发生之前。

I need to intercept when the system tries to access to a file, and do something before it happens.

推荐答案

您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx"><$c$c>FileSystemWatcher - 但是,这并不让你截获该事件,做事前手 - 它只是告诉你一个事实,即一个特定的文件或目录已影响到以某种方式后

You can use FileSystemWatcher - but this doesn't let you intercept the event and do things before hand - it only informs you after the fact that a particular file or directory has been affected in some way.

截取文件访问是不是你可以很容易做到。

Intercepting file access is not something you can do easily.

您可以编写一个文件系统过滤驱动,这是一个非托管的DLL文件,将O / S将加载,可以对文件或文件夹 拦截行动。然而,这不是一个简单的任务。

You can write a file system filter driver, which is an unmanaged DLL which the O/S will load that can intercept operations on files or folders. However, this isn't a trivial task.

什么是你想达到的,也许还有一个更简单的方法吗?

What are you trying to achieve, perhaps there's a simpler alternative?

这篇关于如何拦截访问文件在.NET程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆