こんにちは。
Windows10でUWPのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。
###前提・実現したいこと
Windows mobileでSJISで保存したテキストファイルを読み込んで、テキストボックスに表示したいです。
###試したこと
下記の通り。
###発生している問題・エラーメッセージ
//'Shift_JIS' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.Parameter name: name
Shift-JIS, Shift-JISいずれもダメでした。
なにと指定すればよいのでしょう?
###該当のソースコード
C#
1 FileOpenPicker openpicker = new FileOpenPicker(); 2 openpicker.ViewMode = PickerViewMode.List; 3 openpicker.SuggestedStartLocation = PickerLocationId.ComputerFolder; 4 //openpicker.SuggestedStartLocation = KnownFolders.RemovableDevices; 5 openpicker.FileTypeFilter.Add(".txt"); 6 StorageFile file = await openpicker.PickSingleFileAsync(); 7 8 try { 9 //var text = await FileIO.ReadTextAsync(file); 10 //textBox.Text = text; 11 12 //var buffer = await FileIO.ReadBufferAsync(file); 13 //DataReader reader = DataReader.FromBuffer(buffer); 14 //byte[] dataBuffer = new byte[buffer.Length]; 15 //reader.ReadBytes(dataBuffer); 16 //string text = Encoding.GetEncoding("Shift-JIS").GetString(dataBuffer, 0, dataBuffer.Length); 17 //textBox.Text = text; 18 19 // エンコーディングを指定して読み込む 20 //using (Stream st = (await file.OpenReadAsync()).AsStream()) 21 //using (TextReader reader = new StreamReader(st, 22 // System.Text.Encoding.GetEncoding("iso-2022-jp"))) { 23 // this.textBox.Text = await reader.ReadToEndAsync(); 24 //} 25 26 using (Stream st = (await file.OpenReadAsync()).AsStream()) 27 using (TextReader reader = new StreamReader(st, System.Text.Encoding.GetEncoding("Shift_JIS"))) { 28 this.textBox.Text = await reader.ReadToEndAsync(); 29 } 30 31 //using (var stream = await file.OpenReadAsync()) { 32 // var size = stream.Size; 33 // using (var inputStream = stream.GetInputStreamAt(0)) { 34 // string text = ""; 35 // var dataReader = new DataReader(inputStream); 36 // var numBytesLoaded = await dataReader.LoadAsync((uint)size); 37 // text = dataReader.ReadString(numBytesLoaded); 38 // textBox.Text = text; 39 // } 40 //} 41 42 } 43 catch (Exception exception) { 44 string error = exception.Message; 45 } 46 } 47 48
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2015
Version 14.0.25424.00 Update 3
Microsoft .NET Framework
Version 4.6.01038
インストールしているバージョン:Community
Visual C# 2015 00322-20000-00000-AA575
Microsoft Visual C# 2015
です。
よろしくお願いします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/22 00:18