UTF-16 Source files in Visual Studio RRS feed

  • Question

  • In Visual Studio, I know that any given file can be saved as UTF-16 by using 'File - Save <filename> as' and selecting the 'Unicode - Codepage 1200' encoding, but doing this for each and every file is a pain and remembering to do it each and every time is error-prone.

    Is there a way to have Visual Studio use UTF-16, by default, for all files (source and otherwise) that it creates so that using 'File - Save ... as' is unnecessary?

    Tuesday, June 30, 2015 8:20 PM


  • Hi Glenn,

    As far as I know, the document encoding depends on the Windows OS. There's no options in VS IDE to change the default document encoding. But you have these options:

    1. Change the file encoding of project templates or item templates, the built-in templates are located in the VS installation folder:

    C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates

    C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates

    whereas the custom templates are located in the document folder:

    C:\Users\<user>\Documents\Visual Studio 2013\Templates\ItemTemplates

    2. Develop a program to loop through all the document files under the project's main folder, save the files as new ones with the corresponding encoding.

    You can either create a separate program or a VS extension, the main code are something like this:

    var content = File.ReadAllText("Class1.cs");
    File.WriteAllText("Class1.cs", content, Encoding.Unicode);

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Caillen Thursday, July 9, 2015 2:07 AM
    Wednesday, July 1, 2015 9:58 AM