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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:50:22+00:00 2026-05-16T13:50:22+00:00

i am trying to read file from a stream. and i am using stream.read

  • 0

i am trying to read file from a stream.

and i am using stream.read method to read the bytes. So the code goes like below

FileByteStream.Read(buffer, 0, outputMessage.FileByteStream.Length)

Now the above gives me error because the last parameter “outputMessage.FileByteStream.Length” returns a long type value but the method expects an integer type.

Please advise.

  • 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-16T13:50:23+00:00Added an answer on May 16, 2026 at 1:50 pm

    Convert it to an int…

    FileByteStream.Read(buffer, 0, Convert.ToInt32(outputMessage.FileByteStream.Length))

    It’s probably an int because this operation blocks until it’s done reading…so if you’re in a high volume application, you may not want to block while you read in a massively large file.

    If what you’re reading in isn’t reasonably sized, you may want to consider looping to read the data into a buffer (example from MSDN docs):

    //s is the stream that I'm working with...
    byte[] bytes = new byte[s.Length];
    int numBytesToRead = (int) s.Length;
    int numBytesRead = 0;
    while (numBytesToRead > 0)
    {
        // Read may return anything from 0 to 10.
        int n = s.Read(bytes, numBytesRead, 10);
        // The end of the file is reached.
        if (n == 0)
        {
            break;
        }
        numBytesRead += n;
        numBytesToRead -= n;
    }
    

    This way you don’t cast, and if you pick a reasonably large number to read into the buffer, you’ll only go through the while loop once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create classes to read from my config file using ConfigurationSection and
i'd like to read binary data from a blob, using the Stream interface around
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy
I am trying to read an XML-file from another server. However the the company
I'm trying to read a value from a file and use it in a
I'm trying to create a Zip file from .Net that can be read from
In order to improve performance reading from a file, I'm trying to read the
I'm trying to read variables from a batch file for later use in the
I'm trying to read data from a.csv file to ouput it on a webpage
I am trying to read in the pixel data from an image file as

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.