System.Net.WebException: Sharing violation on path

0

I'm creating an app in Xamarin for android that when you finish your task, create a PDF with iTextSharp.

I have a problem since this app has a SignaturePad, it captures the signature and inserts it into the PDF.
When I capture the signature for the first time I do not have any problem, but when I do it for the 2nd time, the following exception occurs:

  

Unhandled Exception:

     

System.Net.WebException: Sharing violation on path /mnt/sdcard/ProjectTest/Firma.jpg

I have no idea what is due, since the image of the signature is being saved without problems and in the PDF before inserting the signature I put 2 or 3 more images and in none of them I have a problem.

I leave here the part where I entered the image so that they can review it, if they need more parts of the code they let me know in the comments:

string RutaFirma = "/mnt/sdcard/ProyectoTest/Firma.jpg";
Image FirmaPaciente = Image.GetInstance(RutaFirma);
FirmaPaciente.ScalePercent(20);
FirmaPaciente.SetAbsolutePosition(380, 150);
document.Add(FirmaPaciente);
    
asked by Matias 20.09.2018 в 22:09
source

1 answer

0

After dealing enough with the issue I found the problem:
The problem was something very basic about IO.

This is the method where the signature is generated:

private async void BtnAceptar_Click(object sender, EventArgs e)
{
    var directory = new Java.IO.File("/mnt/sdcard", "ProyectoTest").ToString();

    if (!Directory.Exists(directory)){
        Directory.CreateDirectory(directory);
    }

    path = System.IO.Path.Combine(directory, "Firma.jpg");

    if (System.IO.File.Exists(path)){
        System.IO.File.Delete(path);
    }

    Stream bitmap = await FirmaPaciente.GetImageStreamAsync(SignatureImageFormat.Png, Color.Black, Color.White, 1f);
    FileStream dest = System.IO.File.OpenWrite(path);
    await bitmap.CopyToAsync(dest);
    FinishAfterTransition();
}

The dest.Close(); was missing before FinishAfterTransition(); !!!

    
answered by 21.09.2018 / 14:41
source