silverlight编码问题
我用OpenFileDialog打开文本文件
文本文件如果是utf-8格式的没问题,默认ANSI就是乱码
silverlight又不支持gb2312
把他转换成byte数组也不行,reader.ReadToEnd()转换之前就已经是乱码了
各位帮忙看一看,谢谢了
OpenFileDialog openFileDialog1 = new OpenFileDialog(); // Set filter options and filter index. openFileDialog1.Filter = "文本文档 (.txt)|*.txt|所有文件 (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = false; // Call the ShowDialog method to show the dialog box. bool? userClickedOK = openFileDialog1.ShowDialog(); // Process input if the user clicked OK. if (userClickedOK == true) { txtFile.Text = openFileDialog1.File.Name; // Open the selected file to read. Stream fileStream = openFileDialog1.File.OpenRead(); using (StreamReader reader = new StreamReader(fileStream, System.Text.Encoding.UTF8)) { byte[] temp = Encoding.UTF8.GetBytes(reader.ReadToEnd().ToString()); string retFax = Encoding.UTF8.GetString(temp,0,temp.Length); //string retFax = reader.ReadToEnd(); txtPhone.Text = retFax; } fileStream.Close(); }