title: iTextSharp generated PDF: How to send the pdf to the client and add a prompt?
body: <p>I have generated a pdf using iTextSharp, when its created it saves automatically in the location provided in my code on the server not on the client side and of course without telling anything to the user.</p>
  
  <p>I need to send it to the client and I need to prompt a dialogue box to ask the user where he wants to save his pdf..</p>
  
  <p>how can i do this please?</p>
  
  <p>this is my pdf code:</p>
  
  <pre><code>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);
      }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>this is an example of the result i want
  <a href="http://examples.extjs.eu/?ex=download">http://examples.extjs.eu/?ex=download</a></p>
  
  <p>thanks to your replies ,I modified my code to this:</p>
  
  <pre><code>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(); 
  </code></pre>
  
  <p>but i get this error:</p>
  
  <pre><code>Uncaught Ext.Error: You're trying to decode an invalid JSON String: 
  %PDF-1.4 %���� 3 0 obj &lt;&lt;/Type/XObject/Subtype/Image/Width 994/Height 185/Length 13339/ColorSpace/DeviceGray/BitsPerComponent 8/Filter/FlateDecode&gt;&gt;stream x���|E�
  ...........
  </code></pre>
  
  <p>im absolutely sure my itextsharp to create pdf is correct because i can save it on the server, but thats not what i need to do ,when i try to send it to the client i got the error above</p>
  
  <p>thanks in advance</p>