How to set up default encoding in Visual Studio 2010 - 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?

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.

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.

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).

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.

Related

How can I open the Visual Studio EditorConfig Designer after changing the default editor for the .editorconfig file type?

Does anyone know how to either add back in the EditorConfig Designer as a program to open files with or how to reset the default editors for file types?
After changing the default editor for .editorconfig files to be something other than the EditorConfig Designer the option to set the default editor back to the designer or to open with the designer is now gone.
I know I can probably delete my appdata folder or something like that and reset it that way, I'm looking for a way to do it that doesn't take doing that. I did a quick search in some of the xml files visual studio uses but realized it would take some time to figure out exactly what to do to add it back in myself, thus I'm asking with hopes someone has experience doing this.
One work around I have found is to set the files to open with a text editor with text encoding then hit cancel when it asks which encoding to use. It then opens the designer but it still won't show up as an option to set as the default or in the open with items, which is what I want.

How can I get Visual Studio 2010 to show Chinese comments properly

I have some code from a Chinese business partner, and all of the comments in the code are in Chinese. However, Visual Studio displays them as gibberish. How can I get them to display properly. Here is a code example with some comments converted to gibberish:
//Á¬½Óµ½·þÎñÆ÷
void CTestAPIDlg::OnBnClickedButton2()
{
UpdateData(TRUE);
//ÉèÖÃÊÇ·ñ¼Ç¼ÈÕÖ¾
m_ObjRSI->EnableLog(m_bIsOnLogReg,m_bIsOnLogComm);
//ÅжÏÊÇ·ñÆôÓôúÀí
if (m_bIsOnProxy)
{
//´úÀí²ÎÊý
char proxyIP[64];
ZeroMemory(proxyUserPwd,sizeof(proxyUserPwd));
//×¢£º´Ë´¦ÒòΪÊÇʹÓÃunicode±àÒ룬ËùÒÔÒª×Ö·ûת»»£¬ÏÂͬ.
WideCharToMultiByte(CP_ACP,0,m_strProxyIP,-1,proxyIP,64,NULL,NULL);
etc...
Thanks in advance for any help...
Ask your partner to save the source code file encoded in UTF-16 or UTF-8. It is still not the default encoding for C++ source code, Unicode is slow to catch up. File + Save As, click on the arrow of the Save button, Save with Encoding, choose UTF-8.
You should be able to do this yourself as well. File + Open, select the .cpp file(s), click on the arrow of the Open button, Open With, select "C++ Source Code Editor (with encoding)". Pick the correct Chinese encoding (there are several to choose from) from the Encoding dialog box.
You can use applocale, download it from here: http://www.microsoft.com/en-us/download/details.aspx?id=13209.
This is an old app but works well on Win7 and Win8 (tested). When installing, simply make sure to run it as admin. Then later on, run devnev.exe (visual studio) using applocale and set the locale to Chinese. I just tested this works perfectly well.
For 2021 Chinese reader using Visual Studio 2019:
On Windows, the Visual Studio 2019 Community is default to use Big5 encoding.

Source encoding in Visual Web Developer 2008 Express

Where can I set it? I need files to be encoded in UTF-8 by default... there is nothing in Tools -> Options or any other menu as far as I know :(
P.S. I don't need to set default encoding for Project or so, I need it to be default for any files I create. Thanks for your help :)
Instead of clicking save click save as. Then click the little down arrow by save to save with encoding. Once this is done it will bring you to the advanced save options which appear in full VS studio. You can then pick UTF-8 as the encoding.
The encoding options are available from a drop down list attached to the Save button when you select Save as..
File -> Advanced save options
Choose Encoding and Line endings
Regards,
Haris
I believe you cannot set the source encoding as a project setting. Instead, it tries to determine the source encoding from the file, using a fairly limited algorithm. Part of that algorithm is
if it has an UTF-8 signature (BOM), it is UTF-8 encoded
otherwise, it is in the ANSI system code page (CP_ACP)
There might be some additional checks in-between (e.g. checking for UTF-16 with BOM also).
In my experience, the "save as" encoding is not very useful, unless saving as UTF-8-with-BOM. You can save it in a different encoding, but in reopening, it will still assume it's CP_ACP.
IIRC, source files in visual studio are already encoded as UTF-8.
However, if I'm wrong or if you just want to force any specific coding, you can do it by choosing the Save As... option for the file and checking the pull down options under the save button from there.
Thank you for your answers but that's not exactly what I need.
Ok I will try to be more specific. That's how it goes: I go to Open website, I open website directly via FTP. On the right hand side I can see file list. I right-click on it, choose new item, html file, I have new html file. I add some text into it, click save (CTRL+S), the file is saved. Now I open it via browser and I see it's not saved in UTF-8. So, can I fix this problem in any way? :)
are you saying that even though the source file is encoded in utf-8, your internet browser is displaying it as ansi? do you have a meta encoding tag defined?
http://tlt.its.psu.edu/suggestions/international/web/tips/declare.html
try this and your browser should say it is utf-8. just saving a file in utf-8 won't do it.

Displaying Japanese fonts in source code using Visual Studio

I have some source files that have comments written in Japanese. When I open these files in Visual Studio they appear like this:
à–¾FNCAP‰¹—p‚̃XƒŒƒbƒh
I am using the English version of WinXP, but is there a way to get Visual Studio to display the actual Japanese characters rather than the random jibberish it currently is?
I found a general solution to the problem. This worked for me in Chinese text for Visual Studio 2013 and Windows 8.1.
per https://msdn.microsoft.com/en-us/library/ms246590.aspx
As Administrator Click Start, click Control Panel, and then open Regional and Language Options (or Region in Windows 8).
Click the Advanced tab. (or Administrative in Windows 8)
In the Select a language to match the language version of the non-Unicode programs you want to use list, select the language you are currently using.
Click OK.
Presumably VS is interpreting the file with the wrong encoding.
Reopen it using "File -> Open -> File... -> Open -> Open With... -> Source Code (Text) Editor With Encoding" and try various encodings.
Have you turned on support for Eastern languages for Windows? I have that turned on and I can see Chinese characters in Visual Studio 2005 on WinXP.
To turn it on you'll probably need the installation DVD for Windows. The setting is under Regional and Language Options in the Control Panel. I think you just need to check the "Install files for East Asian languages" option.
Microsoft's support page for internationalization has some screenshots and instructions.
I faced the same issue and have found a solution that works for me.
The problem is that the files aren't unicode and VS is trying to open them with an encoding that matches your location. Luckily, you can set Windows default behavior for non-unicode files. Check out this link, http://msdn.microsoft.com/en-us/library/ms246590.aspx. Look under "To correctly display characters that are not included in the current code page."
These directions are incorrect for Windows 8 (I can't speak for 7 or older.) For Windows 8:
Navigate to Control Panel
Select Clock, Language, and Region (yeah they still have the comma before and)
Region
Administrative
Change System Locale...
Select the desired language from the "Current System Locale" drop down
Most of your programs should continue to function in English as this setting is only applied when programs and files don't support unicode.
i have just gotten this problem and fixed it by changing config "files.encoding" in file "setting.json" . Go to Menu => File => Reference => setting to open the file. Search for "files.encoding" and change value to Encoding of your file (my file encoded in Shift-JIS , i checked ending by using Notpad++)
Windows 10 : --> Control Panel\Clock and Region\Region
You can also convert the text encoding to UTF-8 using Notepad++.
Originally encoded as Shift-JIS:
Convert to UTF-8:
Save file.
It should now display correctly regardless of local region.

Copy-paste code from Visual Studio, but paste UNFORMATTED code

Is there any way to force Visual Studio to copy selected code to the clipboard as unformatted text?
When I am copy-pasting code into Word or more often Outlook I have to do it via Notepad to get rid of the formatting...there has to be an easier way!
This feature can be turned off by editor.copyWithSyntaxHighlighting.
Visual Studio does put unformatted text on the clipboard, but it also puts formatted text. (The clipboard supports multiple simultaneous formats, and the OS assumes that they're simply different representations of the same data, although there's no technical enforcement of that point.)
The application you're using to paste then chooses its preferred format. In Word, and maybe Outlook as well, there is a "Paste Special" command that allows you to choose which format you want to use.
My department uses PureText. Sits in the system tray; copy text, click-it - strips all formatting leaving the plain-vanilla text. I'm sure it's much like PlainTextClipboard.
"PureText is basically equivalent to
opening Notepad, doing a PASTE,
followed by a SELECT-ALL, and then a
COPY. The benefit of PureText is
performing all these actions with a
single Hot-Key and having the result
pasted into the current window
automatically."
The goad for this was flaky Lotus Notes; likes to crash when pasting HTML-marked-up-text that I innocently copied from a web-page....
If you press CTRL+Z after pasting, it will reverse to the non-formatting one, because the formatting actually counts as one step after the regular paste.
When I do it choosing the little pop-up menu option attached to the wee clipboard item "Match Destination Formatting" does the trick for me.
From this blog post I got these instructions for getting rid of the black background when copying & pasting out of VS with the 'Dark Theme' activated, but the html in it can be tweaked to alter the rest of the formatting as required (e.g. set all text to black).
If required, install Productivity Power Tools
Open Tools → Extensions and Updates
Select Online (Visual Studio Gallery) and search for Productivity Power Tools 2012/2013
Download and restart Visual Studio when prompted
Productivity Power Tools Settings
Open Tools → Options → Expand Productivity Power Tools
select HTML Copy
Change the BeforeCodeSnippet option to:
<style type="text/css">.identifier {color:black !important;}</style>
<pre style="{font-family}{font-size}{font-weight}{font-style}">
Change EmitSpanClass to: True
Check EmitSpanStyle is: True
You might find http://www.extrabit.com/plaintextclipboard/ to be a useful tool. Some applications have a paste option which strips formatting, but what you really need is a copy operation that strips formatting, which VS does not offer.
In Outlook 2007, I've changed my default paste to do text only.
Go to Editor Options | Advanced
Under the "Cut, copy, paste" heading choose Pasting from other programs: [Keep Text Only]
And if you still want to paste formatted (less often in my case), use paste special...
Search editor.copyWithSyntaxHighlighting in Settings and disable it. Whoever enabled it by default must be flogged.
This Microsoft Office site offers a workaround that involves writing a macro to replace ctrl+v functionality to paste plain text all the time, but that may not be what you want. You can alternatively remap an unused shortcut (ctrl+?) to provide you with this functionality so you don't have to keep enabling / disabling the macro.
For applications that do not have a "paste special" you could use an application like PureText
The Visual Studio Extension Copy for review may be handy for you. Actually, it does not do unformatted copying, but applies it's own simple text-based template.
It supports a "Stack Overflow" format, which just removes the leading whitespace, while keeping the indentation as much as possible, and introduces some sort of header.
Get it from the from the Visual Studio Gallery and try it out.
Disclosure: I am the author of that Extension. Please notfiy me, if I can improve it to your needs.
A trick when applies:
You don't want to install an extension
Your destination application doesn't have options such as "Paste Special"..
You can copy the code and paste it in VS Code search box (shows when you press Ctrl+F). Then copy it again from there.
Then you can paste unformatted text anywhere you want.

Resources