According to several answers here on SO, eg. How can I detect the encoding/codepage of a text file it is not possible to retrieve the encoding of a file.
How does VS do it then? If I "Save as", and select "Save with encoding" it shows the current encoding of my file.