tags:

views:

156

answers:

2

Consider a network folder:

\\desiis\c$\Company\B2b\Monitor

On that machine, any process that tries to delete the directory Monitor receives an error because a user on the LAN has that directory open (likely with Windows Explorer).

Can I detect, via C# and .NET framework, if any user (and which user) has a particular directory open/in use?

+1  A: 

No, there is no possibility I know.

It seems you'll have to catch the occuring Exception as a workaround.

winSharp93
it's a pity :'( perhaps, any guru of Microsoft will have a solution... I pray for it...
Alhambra Eidos
+1  A: 

I'm not sure if you can obtain the particular user in the directory but the DirectoryInfo class in C# .NET would probably be the best way to go.

http://msdn.microsoft.com/en-us/library/system.io.directoryinfo%5Fmembers.aspx

Review the API at this link and you'll notice there is a method to get the information about WHEN the directory was last accessed but not by who. Also you can catch any exception when trying to delete a directory as it being unavailable (an exception will be thrown as you are probably well aware).

Also note that exception catching is costly and you should evaluate any slowdowns in your process by doing this.

ajdams
I need API kernel32.dll (any method, which??) about it (for knows the user who uses the directory) ?? thanks !!!
Alhambra Eidos