How to detect if a file is accessed (Opened)

  • Thread starter Martin Arvidsson, Visual Systems AB
  • Start date
M

Martin Arvidsson, Visual Systems AB

Hi!

I want to create an event that is fiered when a file is accessed (Opened).

What i want to do is monitor a directory and subdirectory if files are
opened.

I have tried to use the FileSystemWatcher. But it didn't work as i expected.
I cant get it to fire an event when a file is accessed.

Any hints? Ideas, Links?

Regards
Martin
 
P

PhilipDaniels

Hi!

I want to create an event that is fiered when a file is accessed (Opened).

What i want to do is monitor a directory and subdirectory if files are
opened.

I have tried to use the FileSystemWatcher. But it didn't work as i expected.
I cant get it to fire an event when a file is accessed.

Any hints? Ideas, Links?

Regards
Martin

It can be done (in Windows at least) - check out the tool FileMon from
www.sysinternals.com for an example. I suspect you will need interop
to the Windows API. Sorry I can't point you to which API call you will
need.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Did you try NotifyFilters.LastAccess ?

If not good enough for you , then you will have to p/invoke some win api
(which should not be nice)


--
Ignacio Machin
machin AT laceupsolutions com


message | Hi!
|
| I want to create an event that is fiered when a file is accessed (Opened).
|
| What i want to do is monitor a directory and subdirectory if files are
| opened.
|
| I have tried to use the FileSystemWatcher. But it didn't work as i
expected.
| I cant get it to fire an event when a file is accessed.
|
| Any hints? Ideas, Links?
|
| Regards
| Martin
|
|
 
M

Martin Arvidsson, Visual Systems AB

Hi!

Yes, but no events are triggered when i open the file.

Do i do something wrong?

Regards
Martin
 
W

Willy Denoyette [MVP]

Martin Arvidsson said:
Hi!

I want to create an event that is fiered when a file is accessed (Opened).

What i want to do is monitor a directory and subdirectory if files are opened.

I have tried to use the FileSystemWatcher. But it didn't work as i expected.
I cant get it to fire an event when a file is accessed.

Any hints? Ideas, Links?

This can't be done from user space, you'll have to write a FS filter driver, something which
is not possible using managed code.
Not sure why you need this though, mind to tell us?

Willy.
 
M

Martin Arvidsson, Visual Systems AB

I am creating a simple RCS.

The thing is we have a 4G development software and it's a bit odd. The new
version simply
locks the development area when a user opens a workspace.

What i want to do is have a master on the server, each developer should have
a local copy.

When a user opens a file for editing on a local computer, it will check what
file is opened. Check against a list. If the file is opened, it will tell
the user that the file is currentlu beeing edited by another user. And a
little more functions which i dont have time to describe right now...

/Martin
 
I

Ignacio Machin \( .NET/ C# MVP \)

message | Hi!
|
| Yes, but no events are triggered when i open the file.
|
| Do i do something wrong?

Post your code, not only you need to correctly set the NotifyEvents but also
you need to assign the correct event handler.

Are you activating the FileSystemWatcher?
 
M

Martin Arvidsson, Visual Systems AB

Hi!

Yes the filewatcher is enabled...

I have assigned every event, Change, Create. etc

But it will not simply raise

If i add all the filters i can se when its changed, created etc. But any
events on when the file is opened is not done.

/Martin
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,



message | Hi!
|
|
| I have assigned every event, Change, Create. etc
|
| But it will not simply raise
|
| If i add all the filters i can se when its changed, created etc. But any
| events on when the file is opened is not done.
|
| /Martin
|
|
| "Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.com> skrev i
| meddelandet | >
in
| > message | > | Hi!
| > |
| > | Yes, but no events are triggered when i open the file.
| > |
| > | Do i do something wrong?
| >
| > Post your code, not only you need to correctly set the NotifyEvents but
| > also
| > you need to assign the correct event handler.
| >
| > Are you activating the FileSystemWatcher?
| >
| >
| > --
| > Ignacio Machin
| > machin AT laceupsolutions com
| >
| >
|
|
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

message | Hi!
|
| Yes the filewatcher is enabled...
|
| I have assigned every event, Change, Create. etc
|
| But it will not simply raise
|
| If i add all the filters i can se when its changed, created etc. But any
| events on when the file is opened is not done.

Sorry, the other post went away before I finished writting it :)

So in that is the case you may have to deal with P/invoke.

Even so, I would advise you to first try to explorer WMI, maybe you have a
way of doing it using WMI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top