Save and open files with encoding

You can save files with specific character encoding in Visual Studio to support bidirectional languages. You can also specify an encoding when you open a file to ensure Visual Studio displays the file correctly.

Prerequisites

Save file with encoding

Follow these steps to save your file with encoding:

  1. In Visual Studio, select File > Save <Filename> As for the file you want to save.

  2. In the Save File As dialog, expand the Save dropdown menu and select Save with Encoding:

    Screenshot that shows how to select the option to save a file with encoding in Visual Studio.

  3. In the Advanced Save Options dialog, use the Encoding dropdown list to select the desired encoding for the file.

  4. (Optional) Use the Line endings dropdown list to select the desired format for end-of-line characters.

    This option is useful if you intend to exchange the file with users of a different operating system.

    If you want to work with a file with a specific encoding, you can instruct Visual Studio to use that encoding when it opens the file. The method you use depends on whether the file is part of your project.

  5. To save the file, select OK.

Note

To save the project file with encoding, first unload the project. The Save File As option isn't enabled until you unload the project.

Open encoded file with project

To open an encoded file located within a project, follow these steps:

  1. In Visual Studio Solution Explorer, right-click the file and select Open With.

  2. In the Open With dialog, select the program to open the file, and select OK.

    Many Visual Studio editors, such as the forms editor, can autodetect the encoding and open the file appropriately.

    If you choose an editor that allows you to specify an encoding, the Encoding dialog opens:

    • In the Encoding dialog, select the encoding for the editor to use, and select OK.

Visual Studio opens your file.

Open encoded file without project

To open an encoded file not located within a project, follow these steps:

  1. In Visual Studio, select File > Open, and then select File.

  2. In the Open File dialog, browse to the file to open, and select the file.

  3. Expand the Open dropdown menu and select Open With.

  4. To complete this process, follow Step 2 in the previous procedure.