title: Writing a text file from VB.NET (encoding)
body: <p>I am writing an application that must generate a plain text file with fixed-sized columns.</p>
  
  <p>My current code is:</p>
  
  <pre><code>Dim MyFilePath As String = Path &amp; FILE_PREFIX &amp; FileNr &amp; ".TXT"
  
  IO.File.Delete(MyFilePath)
  
  Dim FileStr As New IO.StreamWriter(MyFilePath, False, &lt;ENCODER HERE&gt;)
  Do While r.Read
      FileStr.WriteLine(r("TXTLine"))
  Loop
  FileStr.Close()
  r.Close()
  </code></pre>
  
  <p>My problem is that I have some special characters like: "ñ", "à", etc., and I can't find the right encoding.</p>
  
  <ul>
  <li>If I use the default, then it replaces
  "ñ" with two characters.</li>
  <li>If I use ASCII then all special
  characters end up as: "?"</li>
  <li>If I use <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow noreferrer">UTF-8</a> then all text is OK,
  but it adds a "ÿ" in the first byte of
  the file.</li>
  </ul>
  
  <p>I need the special characters to be written in the textfile just as they came in the datareader. And I can't have extra characters added because columns are of fixed lenght...</p>
  
  <p>What could I do?</p>