title: How to properly serve a PDF file
body: <p>I am using .NET 3.5 ASP.NET.  Currently my web site serves a PDF file in the following manner:</p>
  
  <p><code>context.Response.WriteFile(@"c:\blah\blah.pdf");</code></p>
  
  <p>This works great.  However, I'd like to serve it via the <code>context.Response.Write(char [], int, int)</code> method.</p>
  
  <p>So I tried sending out the file via </p>
  
  <pre><code>byte [] byteContent = File.ReadAllBytes(ReportPath);
  ASCIIEncoding encoding = new ASCIIEncoding();
  char[] charContent = encoding.GetChars(byteContent);
  context.Response.Write(charContent, 0, charContent.Length);
  </code></pre>
  
  <p>That did not work (e.g. browser's PDF plugin complains that the file is corrupted).</p>
  
  <p>So I tried the Unicode approach:</p>
  
  <pre><code>byte [] byteContent = File.ReadAllBytes(ReportPath);
  UnicodeEncoding encoding = new UnicodeEncoding();
  char[] charContent = encoding.GetChars(byteContent);
  context.Response.Write(charContent, 0, charContent.Length);
  </code></pre>
  
  <p>which also did not work.</p>
  
  <p>What am I missing?</p>