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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:54:04+00:00 2026-05-19T21:54:04+00:00

I have a BLOB from an Oracle database. In .NET it is of type

  • 0

I have a BLOB from an Oracle database. In .NET it is of type OracleLob and has among them a Read and ReadByte methods.

int OracleLob.Read(byte[] buffer, int offset, int count)
int OracleLob.ReadByte()

So the Read method reads a sequence of bytes and ReadByte reads a single byte at a time. Here is my code:

OracleLob ol = (OracleLob) cmd.Parameters[1].Value; //her er filen!!

BinaryWriter binWriter = new BinaryWriter(File.Open(@"D:\wordfile.DOCX", FileMode.Create));
int currentByte = ol.ReadByte();

while (currentByte != -1)
{
   binWriter.Write(currentByte);
   currentByte = ol.ReadByte();
}

binWriter.Close();

But when I open wordfile.DOCX in Word, it says that the file is corrupt and cannot be opened. What am I doing wrong?

  • 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-19T21:54:05+00:00Added an answer on May 19, 2026 at 9:54 pm

    What’s wrong with the code is that it’s using an int value when writing the byte data to the BinaryWriter. It’s using the overload that is writing an int instead of the one writing a byte, so each byte from the source will be written as four bytes. If you check the file size you see that it’s four times as large as it should be.

    Cast the value to byte so that the correct overload of the Write method is used:

    binWriter.Write((byte)currentByte);
    

    To do this more efficiently, you can use a buffer to read blocks of bytes instead of a single byte at a time:

    using (FileStream stream = File.Open(@"D:\wordfile.DOCX", FileMode.Create)) {
      byte[] buffer = new byte[4096];
      int len = ol.Read(buffer, 0, buffer.Length);
      while (len > 0) {
        stream.Write(buffer, 0, len);
        len = ol.Read(buffer, 0, buffer.Length);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some files stored in a database blob column in Oracle 9. I
I have some python code that: Takes a BLOB from a database which is
I have problem retrieving a blob object from oracle DB to java API with
I have this php code that grabs binary( blob ) data from the database
I downloaded the JSON2.js from https://github.com/douglascrockford/JSON-js/blob/master/json2.js and it does not have implementation for JSON2.stringify()
I have a listview, baseadapter and data from SQLite, including a BLOB. What if
I have a blob saved in my database (a text file). I can retrieve
I have an existing database containing some pictures in blob fields. For a web
The table columns have the data type BLOB and CLOB. What are the corresponding
I have a database which contains picture data stored as a binary blob. 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.