VB.NET determine if a file is ASCII text before opening?

Tony Lewis 1 Reputation point
2021-10-26T00:01:37.4+00:00

One can select a file via OpenFileDialog, and set the file filters to .TXT or other extensions to limit input files to text based files. However, it is possible to have an ASCII text file that has no extension, or the wrong extension. Likewise, binary files can have .txt or other file extensions when they are not text based.

Is there a way to check a file when selected and determine if its contents are ASCII text based before (or after) the file contents are read?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
{count} votes