title: How can I distinguish between a binary file and a text file using dot-net languages
body: <p>I have a visual basic program that downloads individual files from the internet.   Those files can be PDFs, or they be actual webpages, or they can be text.   Normally I don't run into any other type of file (except maybe images).
  It might seem easy to know what type of file I'm downloading, just test the extension of the URL.   </p>
  
  <p>For instance, a URL such as "<a href="http://microsoft.com/HowToUseAzure.pdf" rel="nofollow noreferrer">http://microsoft.com/HowToUseAzure.pdf</a>" is likely to be a PDF.   But some URLs don't look like that.  I encountered one that looked like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>http://www.sciencedirect.com/science?_ob=MImg&amp;amp _imagekey=B6VMC-4286N5V-6-18&amp;amp _cdi=6147&amp;amp _orig=search&amp;amp _coverDate=12%2F01%2F2000&amp;amp _qd=1&amp;amp _sk=999059994&amp;amp wchp=dGLSzV-lSzBV&amp;amp _acct=C000000152&amp;amp _version=1&amp;amp _userid=4429&amp;amp md5=d4d53f46bdf6fb8c7431f4a2e04876e7&amp;amp ie=f.pdf </code></pre>
  </div>
  </div>
  </p>
  
  <p>I can do some intelligent parsing of this URL, and I end up with a first part:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>http://www.sciencedirect.com/science</code></pre>
  </div>
  </div>
  </p>
  
  <p>and the second part, which is the question mark and everything after it.  In this case, the first part doesn't tell me what type of file I have, though the second part does have a clue.   But the second part could be arbitrary.   So my question is, what do I do in this situation?   Can I download the file as 'binary' and then test the 'binary' bytes I'm getting to see if I have either </p>
  
  <p>1) text   2) pdf   3) html?</p>
  
  <p>If so, what is the test?   What is the difference between 'binary' and 'pdf' and 'text' anyway - are there some byte values in a binary file that would simply not occur in a html file - or in a Unicode file, or in a pdf file?</p>
  
  <p>Thanks.</p>