My access is being denied by executing the following code

Asked

Viewed 640 times

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");
}
  • 2

    Try running Visual Studio in administrator mode.

  • Normally denied access error may be that the path you are trying to access doesn’t even exist. This has happened to me before and I kept thinking that it could be something of access, but in the end, it was I who was passing the wrong way!

  • Can that quote there, from PDF's?

  • @Marcelouchimura Yes, "Arnaldo" :)

1 answer

0

The problem may arise from two points:

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

The fact of the folder "PDF’s" having an apostrophe or an apostrophe does not help much either, it may be causing some problem in the creation of the file. It may not even pose a problem, but you should review the name anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.