That's depending a little bit too much on an implementation detail, IMO.
Granted, file access is probably ALWAYS going to be done through the
P/Invoke layer, but the assumption that there will be no calls to the
P/Invoke layer between the throwing of the exception and the next call to
GetLastWin32Error is a brittle suggestion, at best.
What the OP should really do is make the call to CreateFile himself, and
interpret the error code (if there is one).
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uB**************@TK2MSFTNGP04.phx.gbl...
"Sergei Shelukhin" <re******@gmail.comwrote in message
news:4c**********************************@t1g2000p ra.googlegroups.com...
>Hi. I catch IOException and want to separate the case when I receive
"The process cannot access the file because it is being used by
another process" error from other possible IOException-s. Checking the
message text is not an option because the app is multilingual and
might use a .NET version that is not English.
Is there any way to do it, some error code or something?
Call Marshal.GetLastWin32Error in your catch handler, and check the Win32
error code.
Willy.