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 8266151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:03:15+00:00 2026-06-08T05:03:15+00:00

I am trying to open a Binary file that I plan on converting to

  • 0

I am trying to open a Binary file that I plan on converting to hex but I am running into issues with reading the file via FileStream,

private void button1_Click(object sender, EventArgs e)
{
    openFD.Title = "Insert a BIN file";
    openFD.InitialDirectory = "C:"; // Chooses the default location to open the file
    openFD.FileName = " "; // Iniitalizes the File name
    openFD.Filter = "Binary File|*.bin|Text File|*.txt"; // FIlters the types of files allowed to by chosen

    if (openFD.ShowDialog() != DialogResult.Cancel)
    {
        chosenFile = openFD.FileName;
        string directoryPath = Path.GetDirectoryName(chosenFile); // Returns the directory and the file name to reference the file
        string dirName = System.IO.Path.GetDirectoryName(openFD.FileName); // Returns the proper directory with which to refernce the file 
        richTextBox1.Text += dirName;
        richTextBox1.Text += chosenFile;
        FileStream InputBin = new FileStream(
            directoryPath, FileMode.Open, FileAccess.Read, FileShare.None);
    }
}

I am receiving an error saying that the access to the path is denied, any ideas?

Now that I have gotten that error taken care of I have ran into another Issue, I can read the binary file, but I want to display it as a Hex file, I’m not sure what I am doing wrong but I’m not getting an output in HEX, it seems to be Int values…

if (openFD.ShowDialog() != DialogResult.Cancel)
        {

            chosenFile = openFD.FileName;
            string directoryPath = Path.GetDirectoryName(chosenFile); 
            string dirName = System.IO.Path.GetDirectoryName(openFD.FileName);
            using (FileStream stream = new FileStream(chosenFile, FileMode.Open, FileAccess.Read))
            {
                size = (int)stream.Length;
                data = new byte[size];
                stream.Read(data, 0, size);
            }

            while (printCount < size)
            {
                richTextBox1.Text += data[printCount];
                printCount++;
            }
  • 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-08T05:03:17+00:00Added an answer on June 8, 2026 at 5:03 am

    Your code is miscommented

    string directoryPath = Path.GetDirectoryName(chosenFile); // Returns the directory and the file name to reference the file
    

    is not the filename, it’s the directory path. You want:

    FileStream InputBin = new FileStream(chosenFile, FileMode.Open,FileAccess.Read, FileShare.None);
    

    Addtionally, if I were to guess based on your intentions, you should update your full function to be:

    private void button1_Click(object sender, EventArgs e)
    {
        openFD.Title = "Insert a BIN file";
        openFD.InitialDirectory = "C:"; // Chooses the default location to open the file
        openFD.FileName = " "; // Iniitalizes the File name
        openFD.Filter = "Binary File|*.bin|Text File|*.txt"; // FIlters the types of files allowed to by chosen
    
        if (openFD.ShowDialog() != DialogResult.Cancel)
        {
            chosenFile = openFD.FileName;
    
            richTextBox1.Text += chosenFile; //You may want to replace this with = unless you mean to append something that is already there.
    
            FileStream InputBin = new FileStream(chosenFile, FileMode.Open,FileAccess.Read, FileShare.None);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to open a zip file with jython using FileInputStream and ZipInputStream. But
I'm trying to copy a chunk from one binary file into a new file.
I'm trying to read a binary file with the following code: open(F, <$file) ||
I am trying open a very large file in Emacs and it fails to
I trying to open C: directly with FileStream without success: new FileStream(C:, FileMode.Open, FileAccess.Read,
I'm trying to open a file for input in Excel with this line :
I'm trying the open a relative path in Ubuntu , but after opening the
I'm trying to open a JSON file from the assets folder with an InputStream
I'm trying to open a file and read from the last point read. My
I'm trying to open a file in Openoffice from terminal and to automatically replace

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.