-3

I'm writing a service to get VARBINARY information from a Vendor's service and insert it in to a database on my network. In the example below oResponseObject is declared as an Object, ExecuteURL is an Object, but is returned as System.IO.MemoryStream.

strURL += APIHelper.GetQueryStringParameter("image_id", reader["ImageID"].ToString()); 
Object oResponseObject = ExecuteURL(strURL, true);

byte[] bytes =  ???

QUESTION: How do I convert that MemoryStream so that it will work with the byte[]? I've already tried Encoding.ASCII.GetBytes and Encoding.UTF8.GetBytes. It will go to the Array and insert in to the database with no problem. When I try to render the graphic I get an error indicating that it's either too big or the file is corrupt.

Michael McGriff
  • 793
  • 10
  • 20
Dave
  • 1
  • 2

1 Answers1

0

You could do this:

byte[] bytes = ((MemoryStream)oResponseObject).GetBuffer();
Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • I'm getting an 'InvalidCastEsception' error now. The error that I'm getting now says: Unable to cast object of type 'System.String' to type 'System.IO.MemoryStream'. Other things I've tried it says that it's a MemoryString. – Dave Dec 11 '14 at 15:12
  • You said what's returned is a `MemoryStream`. This is clearly not the case. You seem to be getting back a string, so you need to tell us what's in that string. Is it base64-encoded? Is it just the file name? What is it? My answer is for the question how to get the bytes from a `MemoryStream`. – Thorsten Dittmar Dec 12 '14 at 07:45