Я создал pdf-файл с помощью iTextSharp, когда он был создан, он автоматически сохраняется в месте, указанном в моем коде на сервере, а не на стороне клиента и, конечно же, не сообщая что угодно пользователю.
Мне нужно отправить его клиенту, и мне нужно вызвать диалоговое окно, чтобы спросить пользователя, где он хочет сохранить свой pdf ..
как я могу это сделать, пожалуйста?
это мой код pdf :
using (MemoryStream myMemoryStream = new MemoryStream())
{
Document document = new Document();
PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);
document.AddHeader("header1", "HEADER1");
document.Open();
//..........
document.Close();
byte[] content = myMemoryStream.ToArray();
// Write out PDF from memory stream.
using (FileStream fs = File.Create(HttpContext.Current.Server.MapPath("~\\report.pdf")))
{
fs.Write(content, 0, (int)content.Length);
}
РЕДАКТИРОВАТЬ
это пример результата, который я хочу http://examples.extjs.eu/?ex=download
благодаря вашим ответам я изменил свой код на этот:
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AppendHeader( "Content-Disposition", "attachment; filename=test.pdf");
using (MemoryStream myMemoryStream = new MemoryStream())
{
Document document = new Document();
PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);
document.AddHeader("Content-Disposition", "attachment; filename=wissalReport.pdf");
document.Open();
//..........
document.Close();
byte[] content = myMemoryStream.ToArray();
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AppendHeader("content-disposition","attachment;filename=" + "my_report.pdf");
HttpContext.Current.Response.ContentType = "Application/pdf";
//Write the file content directly to the HTTP content output stream.
HttpContext.Current.Response.BinaryWrite(content);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
но я получаю эту ошибку:
Uncaught Ext.Error: You're trying to decode an invalid JSON String:
%PDF-1.4 %���� 3 0 obj <>stream x���|E�
...........
я абсолютно уверен, что мой itextsharp на создание pdf правильно, потому что я могу сохранить его на сервере, но это не то, что мне нужно делать, когда я пытаюсь отправить его клиенту, я получил ошибку выше
заранее спасибо