测试网址 http://silverlight.services.live.com/invoke/84388/Bin2Text/iframe.html
注意:大文件会很慢
- using System.IO;
- using System.Windows;
- using System.Windows.Controls;
- namespace Bin2Text
- {
- public partial class Page : UserControl
- {
- private TextBox result = new TextBox();
- public Page()
- {
- InitializeComponent();
- this.LayoutRoot.Children.Add(this.result);
- this.result.TextWrapping = TextWrapping.Wrap;
- OpenFileDialog diag = new OpenFileDialog();
- if (diag.ShowDialog() == true)
- {
- FileStream stream = diag.File.OpenRead();
- long count = stream.Length - 1;
- this.result.Text += "byte[] result = new byte[]/n";
- this.result.Text += "{/n ";
- for (int i = 0; i < count; i++)
- {
- this.result.Text += string.Format("0x{0:X2}, ", stream.ReadByte());
- if ((i + 1) % 8 == 0) this.result.Text += "/n ";
- }
- this.result.Text += string.Format("0x{0:X2}/n", stream.ReadByte());
- this.result.Text += "};/n";
- stream.Close();
- this.result.SelectAll();
- }
- }
- }
- }