views:

118

answers:

4

Is it possible in the Windows environment to detect if a file is being opened with with .NET

I would like to place a handler on the file system to detect if a file or any file is being opened, is this possible?

+1  A: 

System.IO.FileSystemWatcher may be what you're looking for.

AFAIK there is no way to detect if a file was opened with .NET or otherwise.

TToni
+5  A: 

The simplest solution would be to use a FileSystemWatcher and set the filter to NotifyFilters.LastAccess, which will tell it to watch for a change in the last access date/time.

Noldorin
+5  A: 

Check out the FileSystemWatcher class

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

I'm not 100% sure that you can determine if a file is opened, but you can determine if a file is changed, created, deleted.

Calanus
+2  A: 

Hi Coppermill,

Some time ago I needed an app to monitor particular folder (and its subfolders) and raise an event if there was a new file created. I used FileWatcher Class. I'm pretty sure that its event 'changed' would work for you. It's nice and simple to implement. Check the sitets below for more info:

usethisaddress msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

usethisaddres csharphelp.com/archives2/archive377.html

Hope this helps.

Damo

damo_inc