Albireo
Albireo

Reputation: 11085

How to set up default encoding in Visual Studio 2010

We're using Visual Studio 2010 professional to develop and maintain our company ASP (classic ASP, not ASP.NET) e-commerce web site, and I'm having file encoding issues every time I create a new page.

Every page in our web site is saved as Windows-1252, and when I create a new page (or randomly when I modify an existing one) Visual Studio saves the page using the UTF-8 encoding, screwing up extended characters or #includes (since the included file is saved as Windows-1252 and the page including it is UTF-8, when displayed the included content goes haywire).

I've tried searching everywhere, but the only solution I found is "Save every file manually with "File" → "Save as" → "Save with encoding", which is quite an hassle to do every time (and I'm totally going to forget to do it sometime).

I already tried deselecting the option "Save documents as Unicode when data cannot be saved in codepage" in "Environment" → "Documents" settings but to no avail.

Am I really stuck with the manual thing?

Upvotes: 13

Views: 13855

Answers (4)

ebk
ebk

Reputation: 616

Lars-Erik's answer does the trick.

Just add some information:

  • For those who want to change default encoding of MFC files, here're the templates:

...\Microsoft Visual Studio 10.0\VC\VCWizards\CodeWiz\MFC\Simple\Templates\LANG_CODE

LANG_CODE is the language of your VS 2010 (1033: en-us, 2052: zh-cn, etc.)

  • In my case, the language of VS is en-us, and MFC template files are all written in English (only ASCII characters) without UTF8 BOM, which means they can be interpreted as either a UTF8 file or a file in my OS code page (cp932). Files created by those templates are treated in cp932 instead of Unicode by default, so I have to add BOM to those templates to make VS 2010 save files explicitly in UTF8 (also with BOM).

Upvotes: 0

Lars-Erik
Lars-Erik

Reputation: 311

I'm way late answering this, but I had the issue myself and this is the first hit on google, so I'll document it here if anyone else wants to know. :)

The default encoding of a new file in Visual Studio depends on the template for that kind of file.

The JavaScript file template for instance recides in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Web\WebNewFileItems\JScript.js (on my box). If you edit that file and save it with your encoding of choice, all new javascript files created with VS will be of that encoding.

Hence you can set the encoding of each file type independently.

Upvotes: 13

C Not
C Not

Reputation: 1

Can't find it, but builtin workaround is, File > Save As > then where the save button is, there is a Down arrow, give you the option of "Save with Encoding"

I select US ASCII Cause I'm getting the BOM on all my documents, once published.

Upvotes: -2

TToni
TToni

Reputation: 9391

I don't know if there is a setting in VS to change the default encoding (though I highly doubt it). You can however quite easily write a little add-in that gives you a "Save as 1252" command which can then be mapped into any menu you like.

Upvotes: 1

Related Questions