ailon's DevBlog: Development related stuff in my life

File Encoding in Visual Studio

11/5/2007 3:43:02 PM

It appears that there's no way to set default file encoding for new files created in Visual Studio 2005 through "Options" and it will save your files in UTF only if it encounters characters it can't save in your systems default non-unicode locale.

What does it mean? It means that if you develop a simple web site in a language of your system (Lithuanian in my case) and you hardcode some local text in your .aspx it will save in non-unicode encoding (Windows-1257 in my case) and when you move it to the server (or other computer) with other default non-unicode encoding all your localized text will be ruined.

What can be done about it? It looks like we have 3 options:

  1. manually save or re-save your files using "Save with Encoding";
  2. change your system language to "English" in control panel (this is kind of wrong);
  3. re-save Visual Studio templates (in Common 7\IDE\ItemTemplates) in UTF-8 with signature

Only the last option somewhat solves the problem but you'll have to go through all of the templates you ever plan to use and hope that this doesn't break anything.

Hopefully this issue will be addressed in VS2008. I had no time to play with the betas yet, so I have no idea if there are any changes in this area. Can anybody confirm this?

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Related posts

Comments

11/5/2007 3:47:11 PM

trackback

Trackback from DotNetKicks.com

File Encoding in Visual Studio 2005

DotNetKicks.com

3/12/2008 8:13:21 PM

Grzegorz Strzalkowski

I think, you are wrong.

VS2005 uses non-unicode machine setting, at least on Vista.

Go to the control panel.
Select regional settings.
Select last tab (Administrative or something).
Click first button.

When it is set to English, we have CP1252 as default in VS.
When it is set to Polish, we have CP1250 as default in VS.

Grzegorz Strzalkowski pl

3/13/2008 5:59:56 PM

ailon

How am I wrong? You wrote the same thing I said just in other words. It saves it in your local non-unicode encoding. Or do I miss something?

ailon lt

3/13/2008 7:39:20 PM

Grzegorz Strzalkowski

Sorry, I think, you are right. I have read your blog in context of my problem, and it was my mistake.

I mean, that there is a way to set specific file encoding for saving files and it can be done through regional settings.

We had a problem, when one of our programmers was corrupting national characters in our source files by opening & saving file only. He was using exactly the same version of Vista and Visual Studio 200. We spent quite a lot of time digging for solution and the problem was in regional settings - he had CP1252 (Western European), but the rest of team had CP1250 (Eastern European).

It seems to be quite important, because we had to repair files manually one by one.

Grzegorz Strzalkowski pl

3/14/2008 9:02:07 AM

ailon

Yes, if you open a file previously saved in 1250 on a system with 1252 it will loose the chars on load. But when you create the file on a system with 1252 and type in some characters that are not in 1252 it will automatically save the file in unicode (as far as I remember).

ailon lt

5/28/2008 4:00:41 PM

Adrian Cimponeriu

I am very grateful for these explications regarding CP1250 encoding standard. It has finally resolved my problem of opening the files transfered through a server client program made in Java#. Many thanks!

Adrian Cimponeriu ro

5/28/2008 4:07:07 PM

ailon

You are welcome!

ailon lt

7/4/2008 6:33:59 PM

Alex

Tools -> Options -> Environment Settings -> Language.

Can't you select English instead of Same as Windows?

Alex

Alex us

7/14/2008 3:43:42 PM

ailon

Alex: this is not about language but encoding in files.

ailon lt

1/27/2009 10:55:57 PM

busby seo test case

thanks for the tutorial..

busby seo test case us

1/29/2009 12:48:39 PM

Busby SEO Test

yap you have good tutorial for us.

Busby SEO Test us

1/29/2009 2:02:45 PM

busby seo test

nice tutorial

busby seo test us

Comments are closed
Copyright © 2003 - 2009 Alan Mendelevich
Powered by BlogEngine.NET 1.3.1.0