title: How can I detect the encoding/codepage of a text file?
body: <p>In our application, we receive text files (<code>.txt</code>, <code>.csv</code>, etc.) from diverse sources. When reading, these files sometimes contain garbage, because the files where created in a different/unknown codepage.</p>
  
  <p>Is there a way to (automatically) detect the codepage of a text file? </p>
  
  <p>The <code>detectEncodingFromByteOrderMarks</code>, on the <code>StreamReader</code> constructor, works for <code>UTF8</code>  and other unicode marked files, but I'm looking for a way to detect code pages, like <code>ibm850</code>, <code>windows1252</code>. </p>
  
  <hr>
  
  <p>Thanks for your answers, this is what I've done.</p>
  
  <p>The files we receive are from end-users, they do not have a clue about codepages. The receivers are also end-users, by now this is what they know about codepages: Codepages exist, and are annoying.</p>
  
  <p><strong>Solution:</strong> </p>
  
  <ul>
  <li>Open the received file in Notepad, look at a garbled piece of text. If somebody is called François or something, with your human intelligence you can guess this.</li>
  <li>I've created a small app that the user can use to open the file with, and enter a text that user knows it will appear in the file, when the correct codepage is used. </li>
  <li>Loop through all codepages, and display the ones that give a solution with the user provided text. </li>
  <li>If more as one codepage pops up, ask the user to specify more text.</li>
  </ul>