473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to detect if a file is accessed (Opened)

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
Jan 23 '07 #1
10 5534
On Tue, 23 Jan 2007 12:39:45 +0100, "Martin Arvidsson, Visual Systems
AB" <ma**************@vsab.netwrote:
>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.

--
Philip Daniels
Jan 23 '07 #2
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
"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:ut**************@TK2MSFTNGP06.phx.gbl...
| 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
|
|
Jan 23 '07 #3
Hi!

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

Do i do something wrong?

Regards
Martin

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comskrev i
meddelandet news:eH**************@TK2MSFTNGP05.phx.gbl...
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
"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:ut**************@TK2MSFTNGP06.phx.gbl...
| 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
|
|


Jan 23 '07 #4
"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
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.

Jan 23 '07 #5
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

"Willy Denoyette [MVP]" <wi*************@telenet.beskrev i meddelandet
news:ux**************@TK2MSFTNGP05.phx.gbl...
"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:ut**************@TK2MSFTNGP06.phx.gbl...
>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.

Jan 23 '07 #6

"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:es*************@TK2MSFTNGP06.phx.gbl...
| 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
Jan 23 '07 #7
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
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comskrev i
meddelandet news:Ob**************@TK2MSFTNGP05.phx.gbl...
>
"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:es*************@TK2MSFTNGP06.phx.gbl...
| 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


Jan 23 '07 #8
Hi,

"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:e9**************@TK2MSFTNGP03.phx.gbl...
| 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.comskrev i
| meddelandet news:Ob**************@TK2MSFTNGP05.phx.gbl...
| >
| "Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote
in
| message news:es*************@TK2MSFTNGP06.phx.gbl...
| | 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
| >
| >
|
|
Jan 23 '07 #9
Hi,

"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:e9**************@TK2MSFTNGP03.phx.gbl...
| 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
--
Ignacio Machin
machin AT laceupsolutions com
Jan 23 '07 #10
Hi,
I found this link
http://forums.microsoft.com/MSDN/Sho...16773&SiteId=1
I think you'll find your answer there

"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:e9**************@TK2MSFTNGP03.phx.gbl...
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
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comskrev i
meddelandet news:Ob**************@TK2MSFTNGP05.phx.gbl...
>>
"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote
in
message news:es*************@TK2MSFTNGP06.phx.gbl...
| 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


Jan 24 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: RC | last post by:
how to detect file is completely downloaded from client by following code? <%@ Page language="C#" debug="true" %> <script language="C#" runat="server"> private void Page_Load(object sender,...
1
by: walter | last post by:
Hi there, this might be a easy one for you -- I want to check if the file is opened by other process before I start to write something in it. This question is so traditional that make me feel a...
7
by: Adam | last post by:
Hello, I want to know if it possible to tell when a file is opened. However I don't want it to be the last access time. I want to know how many times a file opened so I can generate statistics...
2
by: hemapooja | last post by:
Hi, I am using vb.Net web application. I am getting the error of system.io. ioexception. The process can't access the file because it is being usrd by another process. when file is opened or...
36
by: Don | last post by:
I wrote an app that alerts a user who attempts to open a file that the file is currently in use. It works fine except when the file is opened by Notepad. If a text file is opened, most computers...
15
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, For some reasons, somewhere in a program, I'd like, if possible, to quickly parse a whole file before rewinding it and letting the...
0
by: lordfallout | last post by:
I'm using filesystemwatcher to monitor a file, but the only trigger i can see are: changed created deleted disposed error renamed here's what i have:
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.