views:

1412

answers:

3

How do I write the following code in classic ASP? I am using this code in an include file.

 byte[] bytes = new byte[stream.Length]

Also it would be great if anyone can say how to create object for StreamWriter in classic ASP.

  Set sw = Server.CreateObject("System.IO.StreamWriter(stream)")

I am not sure about the code inside quotes System.IO.StreamWriter(stream).

A: 

I don't think there's a direct translation to StreamWriter. My classic ASP objects knowledge is limited, but IIRC the closest match would be FileSystemObject. As for the byte array:

Dim bytes(stream.Length-1) As Byte
Joel Coehoorn
+2  A: 

Classic ASP is just plain old VBScript. CreateObject creates a COM object using the classid/progid: CreateObject("ADODB.Connection") or CreateObject("Scripting.FileSystemObject").

Classic ASP can use COM objects that are actually .NET objects... but only if they have been built specifically supporting COM interop. Most of the internal .NET stuff was not built supporting COM interop.

See: http://msdn.microsoft.com/en-us/library/zsfww439.aspx

If you just need a stream object (not necesarily a .NET System.IO.Stream object) then I'd recommend ADODB.Stream.

Also not that in ASP/VBScript all variables are variants. This makes things like an array of bytes tricky. You can have an array of variants no big deal, and all the variants could be bytes... but you can't create an array that can only hold bytes. To make matters stranger... if a COM object returns a SAFEARRAY of bytes then ASP/VBScript is happy to use it.

A: 

Not sure what you want to do, but..

When I wanted to handle byte arrays from vbscript like a BLOB coming from a database I made a general VB6 COM object that could perform operations on the byte array.

http://www.di-mgt.com.au/bytearrays.html

ssorrrell