My access is denied when executing the following code

1
private void GerarPDF(string pCaminhoArquivoPDF)
{
    Document doc = new Document();

    // Aqui acontece o erro
    PdfWriter.GetInstance(doc, new FileStream(pCaminhoArquivoPDF,FileMode.Create));

    try
    {
        Paragraph p = new Paragraph(textBox1.Text);
        doc.Open();
        doc.Add(p);
        doc.Close();


    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.StackTrace);
        //throw;
    }
}

private void OndeGerar(Object o,EventArgs e)
{
    GerarPDF( @"C:\Users\CAIO\Desktop\PDF's");
}
    
asked by anonymous 30.06.2018 / 20:13

1 answer

0

The problem can be caused by two points:

  • Write Permissions in the C:\Users\CAIO\Desktop\PDF's
    • In this case assign write permissions to the user
  • Lack of writing privileges from Visual Studio itself (or from the IDE you are using to run the code)
    • In this case run the IDE in Administrator mode

The fact that the " PDF's " folder has a quote or apostrophe does not help too much, it may be causing some problem in creating the file. It may not even pose a problem, but it should anyway revisit the name.

    
04.07.2018 / 16:39