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.
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):
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
whileloop once.