Convert Object to Byte array

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
Nikolay Petrov said:
How can I convert variable of type Object to Byte array?

If the object's type is marked with 'Serializable' and supports
serialization, you can use a 'BinaryFormatter' to convert it to a byte
array. I am just curious why you need that...
 
I've found a sample code, which gives me an error when Option Strict is
on
I got this error at: "Response.BinaryWrite(objXml.responseBody)"
responseBody is Object and BinaryWrite method accepts Byte array

code:
'*** Declare the variable
Response.Buffer = True
Dim objXml As New MSXML2.ServerXMLHTTP()
Dim strServer As String

strServer =
"HTTPS://www.myweb.com/myfolder/mysecurity/mydocuments/mydoc.pdf"

'*** Call the ServerXMLHTTP object
objXml.open("GET", strServer, False, "Bob", "1S34EXW")

'Set the Content type of the request sent
objXml.setRequestHeader("Content-Type", "text/html")

' Send the Request to the server
objXml.send()

'** Trap the Response and display the pdf document in a browser
Response.ContentType = "application/x-msdownload"
Response.AddHeader("Content-Disposition", "filename=download.pdf")
Response.BinaryWrite(objXml.responseBody)

'** Try the Streams to read the response
'** Kill the instance
objXml = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top