Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:14:44+00:00 2026-06-04T23:14:44+00:00

i am trying to learn C# so, i watch tutorials and follow them step

  • 0

i am trying to learn C# so, i watch tutorials and follow them step by step, but i also like to add some small things to the programs they do in tutorials. this time i was watching thenewboston C# tutorial about file streaming, i want to create a text reading program which could both read byte-s and normal texts, so i created 3 buttons, 2 for choosing how the reader should show the text and 1 for opening file dialog, but something is wrong with byte reader when i choose that option it only show’s zeros.

this is how my program looks likemy program

this is how my text file looks likemy text file

this is how my result looks like when choosing byte optionenter image description here

this is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.IO;

namespace sound
{
    public partial class Form1 : Form
    {
    bool bytebuttonclicked = false;
    bool normalbuttonclicked = false;
    string text1;
    public Form1()
    {
        InitializeComponent();
    }
    SoundPlayer My_JukeBox = new SoundPlayer(@"C:\WINDOWS\Media\tada.wav");

    private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog OFD = new OpenFileDialog();

        if (OFD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            StreamReader sr = new StreamReader(File.OpenRead(OFD.FileName));
            if (normalbuttonclicked == true && bytebuttonclicked == false)
            {
                textBox1.Text = sr.ReadToEnd();
                sr.Dispose();
            }
            else if (bytebuttonclicked == true && normalbuttonclicked == false)
            {
                text1 = sr.ReadToEnd();
                byte[] Buffer = new byte[text1.Length];
                sr.BaseStream.Read(Buffer, 0, text1.Length);
                foreach (byte MyByte in Buffer)
                    textBox1.Text += MyByte.ToString("X") + " ";
                sr.Dispose();
            }
            else
            {
                MessageBox.Show("choose one button");
            }
        }
        My_JukeBox.Play();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        bytebuttonclicked = true;
        button1.Enabled = true;
    }

    private void button3_Click(object sender, EventArgs e)
    {
        normalbuttonclicked = true;
        button1.Enabled = true;
    }
}
}

So i don’t understand why the program shows me zeros, what’s wrong with my program and how can i improve it?
thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:14:47+00:00Added an answer on June 4, 2026 at 11:14 pm

    First ReadToEnd call reaches to the end of stream, so next sr.BaseStream.Read call tries to read ahead of end of the file hence all zeros. You can either:

    • Convert already read text1 to bytes instead of re-reading if you don’t care about the data loss during encoding.

    or

    • Reset the position of the stream (not reader) by setting stream’s (result of File.OpenRead operation) Position property.

    or

    • Re-open the stream.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to learn and practice arrays but I have a problem with this small
I'm trying to learn Java but it just seem like there are too many
Im trying to learn OOP but I need to see some real case scenarios
Trying to learn about php's arrays today. I have a set of arrays like
im trying to learn how to use javascript objects, and got some issue here.
Im trying to learn a bit about c++ and have run in to some
Trying to learn F# but got confused when trying to distinguish between fold and
Trying to learn some R after doing mostly Haskell for rather a long time
Trying to learn some F# and I've run into a couple of hangups. Here's
trying to learn some html/css and I'm having a problem with fixed position divs.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.