Check if a file is used by an other process
-
I'm writing a program (Vis. C# .NET) to move files, depending from content, to a backup server. Sometimes the file cannot be deleted afdter copying because it is opened by an other process. The best would be to have a test a first that gives me a result if a specific file is opened by an other process or not. How this can be done ? At least I need a boolean answer if the file is opened in this moment by anything other or not. The better way would be to have an answer which process has opened it. Can anybody give me a hint for a good solution ? Holger
-
I'm writing a program (Vis. C# .NET) to move files, depending from content, to a backup server. Sometimes the file cannot be deleted afdter copying because it is opened by an other process. The best would be to have a test a first that gives me a result if a specific file is opened by an other process or not. How this can be done ? At least I need a boolean answer if the file is opened in this moment by anything other or not. The better way would be to have an answer which process has opened it. Can anybody give me a hint for a good solution ? Holger
I would think that you could just try to open the file for exclusive read access - that should throw an exception. As for the ultimate, you would have to use interop and Win32 functions to delve into the finer details. The OpenFile() Win32 function might do a better job than .Net for what you want. This site really helps with the interop stuff.... http://pinvoke.net Jon Humphreys ActivePlanet Software Bangkok, Thailand