0

I get an IOException with ERROR_SHARING_VIOLATION = 32, and I want get the full path file is "locked".

    var ioex = ex as IOException;

    var err = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
    if (err == 32) Trace.WriteLine("It's locked");

The exception message can be in several languages:

The process cannot access the file 'C:\Users\mj.PG\Documents\IssuedLetter\3.PDF' because it is being used by another process.

El proceso no puede obtener acceso al archivo '\xxxx.es\xxxxx\Campañas SVT\Campaña zzzz\Coordinacion\4_ESTADISTICAS\2021\05_mayo\Informes Servicio zzzz\Informe Acumulado\Informe Acumulado 05_05_2021.xlsx' porque está siendo utilizado en otro proceso.

How-to get the full path file without use the string?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
  • 1
    Typically one would know the file they were trying to access. Is that option not available? `IOException` does not provide any way of finding out the file other than parsing the message which is, admittedly, not ideal. – Martin May 07 '21 at 12:19
  • Perhaps look in the `Data` property? –  May 07 '21 at 12:25

0 Answers0