The only way to reliably do this is to find the byte order bytes at the beginning of the text file. (This blob is generally a character encoding encoding, as well as encoding, for example, UTF8, UTF16, UTF32). Unfortunately, this method only works for Unicode-based encodings, and nothing before that (for which you need to use much less reliable methods).
The type StreamReadersupports the detection of these labels to determine the encoding - you just need to pass the flag to the parameter as such:
new System.IO.StreamReader("path", true)
stremReader.CurrentEncoding, , . , , - , CurrentEncoding Encoding.Default.