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

  • SEARCH
  • Home
  • 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 6631459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:32:57+00:00 2026-05-25T22:32:57+00:00

Basically I have have a program that creates an array of bytes (manually entered

  • 0

Basically I have have a program that creates an array of bytes (manually entered via a richtextbox and I want to be able to create a new file and save the bytes in that file via a SaveFileDialog() method.

The code I have come up with is:

byte[] bytes = Encoding.ASCII.GetBytes(richTextBox1.Text);
Stream stream = new MemoryStream(bytes);

SaveFileDialog file = new SaveFileDialog();
file.ShowDialog();

     if (file.FileName != "")
     {
         using (BinaryWriter bw = new BinaryWriter(stream)) 
         {
             bw.Write(bytes); 
         }


     }
  • 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-05-25T22:32:57+00:00Added an answer on May 25, 2026 at 10:32 pm

    You say you’ve got the bytes “manually entered via a richtextbox” – but you’re just getting the ASCII-encoded value of the text. If you were expecting that to (say) parse hex, then you’ll be disappointed. It’s not really clear what you’re trying to do, but if you are trying to save text, you don’t need to convert it into a byte array yourself.

    Next, you’re currently writing to a MemoryStream, so it’s clearly not going to save to a file… if you really wanted to do this, you should use a FileStream instead (either constructed directly or via File.OpenWrite etc). However, you don’t need to do all that work yourself…

    The simplest way to save a bunch of bytes is:

    File.WriteAllBytes(file.FileName, bytes);
    

    The simplest way to save a string is:

    File.WriteAllText(file.FileName, text); // Optionally specify an encoding too
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java program that generates Java classes for my application. Basically it
Basically, I want to have my program retrieve various variables from the hard drive
I have a program that accepts a Cmd command as a command argument. Basically
I have a gridview control in my c# program. Basically someone enters an email
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
That may sound a little confusing. Basically, I have a function CCard newCard() {
i'm trying to create a program that generates images for use as multi-screen backgrounds,
I have this piece of code that basically checks if one or more files
I have dynamic array in struct and a method that uses the dynamic array.
Basically my entire program is to have shapes move across a JFrame, and the

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.