title: ASP.Net C# generate and download PDF File
body: <p>I'm trying to generate and download a pdf file. It keeps saying that the file type is wrong or that the file is damaged.</p>
  
  <p>Here is my code</p>
  
  <pre><code> protected void downloadFile(int index)
      {
  
          string strContent = "&lt;html&gt; &lt;body&gt; &lt;div&gt; &lt;b&gt; Tjeu! &lt;/b&gt; &lt;/div&gt; &lt;div&gt; &lt;INPUT TYPE=CHECKBOX NAME=\"maillist\" disabled=\"disabled\"&gt;Yes! Put me on the list! &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;";
          string attach = "attachment; filename=wordtest.pdf";
          HttpContext.Current.Response.Clear();
          HttpContext.Current.Response.Charset = "";
          HttpContext.Current.Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf;
  
          HttpContext.Current.Response.AddHeader("content-disposition", attach);
  
          HttpContext.Current.Response.Write(strContent);
          HttpContext.Current.Response.End();
          HttpContext.Current.Response.Flush();
      }
  </code></pre>
  
  <p>Thx for the help ;)</p>