How to intercept the access to a file in a .NET Program

后端 未结 5 1071
梦如初夏
梦如初夏 2021-02-20 05:37

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

5条回答
  •  孤城傲影
    2021-02-20 06:00

    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.

    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?

提交回复
热议问题