tags:

views:

268

answers:

4

I have a situation where people are connected to files on a share and it's blocking me from overwriting the file. I'm trying to write a method that will look to see if a filePath that I provide is currently locked in this way and close the network session of this resource.

I looked at the ADSI Winnt provider but the Resources.Remove member isn't implemented. Then I looked at Win32_ServerSession and while I am able to use Delete member, it kills all of the resources for a given user. I need to figure out how to be more specific.

I've been walking GetRelationsShips and Properties but I'm just stumped at the moment.

+1  A: 

I've got no idea if you can even do that - and if you can is it wise? Alternative - can you send a message to the user somehow - email, via the app, etc?

Adrian K
A: 

I would suggest looking at the File class as it contains all of the items you need. link text

mstrickland
+1  A: 

It would be difficult to consider all the ramifications of doing this because you can't necessarily predict the resulting behavior of the application that currently has the file locked.

Is there some other way to do this? For example do you have to overwrite the file right away, or can you have some external process that continually tries to overwrite the file every few minutes until it succeeds?

Jeremy
I'll give you the "don't do that" answer. :-) I know I didn't give the reasons for why I needed to do this but they were real. Fortunatly I handed the task off to someone else though. :-)
Christopher Painter
+1  A: 

Hi !

I faced the same problem. So far I know, the only way to do that, is using the Win32API:

[DllImport("Netapi32.dll", SetLastError=true, CharSet = CharSet.Unicode)]
public static extern int NetFileClose(string servername, int id);

I made a short attempt to realize this and I can just enum the files right, but in my code - I had just a look into it - the code to close a file is set to be a comment. If you would give this a try, I can you sent a library [wrapper around NetFileXXX] and a short demo, but, as I said: I never closed a file. But this is possibly a short way to that.

I do not know, how to interchange file on stackoverflow now :-( ?!?

br--mabra

mabra