CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jun 2005
    Posts
    4

    Read Binary File into ListBox Problem

    Hi,
    Been trying everything to open a binary file into a listbox
    and basically just getting a 0 in the box or with the code below
    at the line = listBox1.Items.Add(br.ReadBytes(((int)br.BaseStream.Length)));
    I will get Byte[]Array in the box, with the streamreader code below that I get
    some binary code in the box, really stuck and need help.
    Thanks
    Steve

    Code:
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                  
                  string filename = openFileDialog1.FileName;
                  FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                  BinaryReader br = new BinaryReader(fs);
                    br.BaseStream.Position = 0;
                    for (int i = 0; i < br.BaseStream.Length; i++)
                    {
                        listBox1.BeginUpdate();
                        listBox1.Items.Clear();
                        listBox1.Items.Add(br.ReadBytes(((int)br.BaseStream.Length)));
                        listBox1.EndUpdate();
                        
                    }
                   br.Close();
                   fs.Close();
                  ///StreamReader streamReader = new StreamReader(filename);
                  ///listBox1.Items.Clear();
                  ///  List<string> lines = new List<string>();
                  ///  string line;
                  ///  while ((line = streamReader.ReadLine()) != null)
                  ///  { listBox1.Items.Add(line); }
    
                }
            }
    Last edited by VictorN; August 16th, 2022 at 01:25 AM. Reason: added CODE tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured