I'm working on a windows form project and it creates a PDF file. I want to save file where user want it to. I use a SaveFileDialog for this. When I click "Save as a PDF" button on my form I get this error code.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
If I don't use the SaveFileDialog (If I give a static name for the file), don't get the error.
Here is button click code:
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments);
saveFileDialog1.Filter = "(*.pdf)|*.pdf|All Files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
iTextSharp.text.Document pdfDosya = new iTextSharp.text.Document(PageSize.A4, 20, 20, 10, 10);
PdfWriter.GetInstance(pdfDosya, new FileStream(saveFileDialog1.FileName, FileMode.Create));//TODO dosya ismi
pdfDosya.Open();
}
}
How can I solve the problem.