Closing Open Files using C#

前端 未结 3 1168
情深已故
情深已故 2021-01-05 16:53

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 f

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-05 17:11

    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

提交回复
热议问题