У меня есть обработчик загрузки PDF:
// Build the PDF
Manual.Functions.createEntireManual(ThisDownload.FileLocation);
// Download file
context.Response.Clear();
context.Response.Buffer = false;
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-disposition", "attachment; filename=Construct2-Manual-Full.pdf");
context.Response.AddHeader("Content-Length", FileSize.ToString());
context.Response.TransmitFile(Settings.ManualBinLocation + ThisDownload.ID + ".pdf");
context.Response.Close();
Функция создания руководства выглядит следующим образом:
public static void createEntireManual(string PDFPath)
{
iTextSharp.text.Document d = new iTextSharp.text.Document();
d.Open();
using (iTextSharp.text.pdf.PdfWriter p = iTextSharp.text.pdf.PdfWriter.GetInstance(d, new FileStream(PDFPath, FileMode.Create)))
{
d.Add(new Paragraph("Hello world!"));
}
}
Это выдает ошибку:
Exception Details: System.IO.IOException: The process cannot access the file 'C:\inetpub\wwwroot\manuals\26.pdf' because it is being used by another process.
Отлично, поэтому я добавляю d.Close()
в мою функцию:
d.Add(new Paragraph("Hello world!"));
}
d.Close();
}
Но это броски:
Exception Details: System.Exception: The document is not open.
На линии d.Close()
. Я попытался добавить новый объект Document в качестве оператора using, но это не понравилось, выдав бессмысленную ошибку:
Exception Details: System.Exception: The document is not open.
Об использовании закрывающей скобки.
Кто-нибудь более опытный с iTextSharp, помогите мне здесь?