Visual Studio 2008のデフォルトファイルコードページ


英語以外の国のプログラムだけが英語国際の人に見られるとコードページの問題があると思っていましたが、英語の国の人も、ASCIIに属さない特殊な文字を使うのが好きで、結果的にそれらのコードが英語以外の国の人に使われるようになったときも、面倒でした.
Visual Studioのデフォルトでは、現在のWindowsコードページを使用してファイルを保存するのは不思議な決定ですが、発生した以上、解決します.インターネットで調べてみると、不思議なことに、多くの人がこの問題を聞いたが、解決策を提供していない.
確かに、Visual Studioのオプションで半日いじったが、デフォルトのコードページを設定できる場所は見つからなかった.
最後に、[ファイル](File)メニューで[拡張保存オプション](Advanced Save Options)を見つけ、コードページを設定してテストします.この設定は新しいファイルにも有効です.デフォルトのコード・ページのようですが、なぜ「オプション」ダイアログ・ボックスに置かないのか分かりません.
また、もう一つの問題は、既存のプログラムをどうするかということです.既製のツールが見つからず、自分で1つ書きました.コードは簡単です.WinFormウィンドウがあります.FileCollectorというListBoxがあります.Runというボタンがあります.FileCountというLabelがあります.それからコードです.

// Recode 1.0
// http://llf.hanzify.org
// http://llf.iteye.com
//   :   
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace Recode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void FileCollector_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Link;
        }

        private void FileCollector_DragDrop(object sender, DragEventArgs e)
        {
            var list = (Array) e.Data.GetData(DataFormats.FileDrop);
            if (list != null && list.Length > 0)
            {
                FileCollector.Items.Clear();
                foreach (object f in list)
                {
                    string s = f.ToString();
                    if (File.Exists(s))
                    {
                        FileCollector.Items.Add(s);
                    }
                }
            }
            FileCount.Text = FileCollector.Items.Count.ToString();
        }

        private void Run_Click(object sender, EventArgs e)
        {
            if (FileCollector.Items.Count > 0)
            {
                foreach (string name in FileCollector.Items)
                {
                    RecodeOneFile(name);
                }
                MessageBox.Show("done!");
            }
            else
            {
                MessageBox.Show("Please drag and drop some files to the list box first.");
            }
        }

        private static void RecodeOneFile(string name)
        {
            string content;
            using (var sr = new StreamReader(name, Encoding.GetEncoding(1252))) //      
            {
                content = sr.ReadToEnd();
            }

            using (var sw = new StreamWriter(name, false, Encoding.UTF8))
            {
                sw.Write(content);
            }
        }
    }
}

個人的には署名付きUTF-8形式が好きですが、ソースファイルのコードページについては、これを調べてもいいです.
コードページの紹介記事 .