G
Guest
I can't be the only one who has faced this!
Objective: store byte array into a string.
Require: the string will be returned to classic ASP, which means that the
content can not be encoded, nor can it be serialized.
Greetings all,
From classic ASP I am accessing C# COM object which is responsible for
network socket communications and returning binary data. The classic ASP is
to take the returned binary data and send it to browser via
Response.BinaryWrite( myBinaryVarient ) to display a PDF document.
In past we did this using VB6 COM objects, where the binary data was stored
in String. However, despite my efforts, I am unable to save binary data into
a string without affecting the data when using C#. Here is a sample code
that demonstrates writing a binary array into a file; and converting the
array into string and then writing it to file. You'll find that the two
files are NOT the same!
Do you have any ideas on this matter...
tnx in advance
// --- Allocate byte array
byte [] arrByte = new byte[255];
for( int i=1; i< arrByte.Length; i++ )
arrByte = (byte)i;
// --- Create two file handlers
string file = "BinaryFile";
FileStream fs1 = new FileStream( file + "1", FileMode.Create );
FileStream fs2 = new FileStream( file + "2", FileMode.Create );
BinaryWriter w1 = new BinaryWriter( fs1 );
BinaryWriter w2 = new BinaryWriter( fs2 );
// --- Econde binary to string
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("iso-8859-1");
string str = enc.GetString( this.arrByte );
// --- Write data to file
w1.Write( str ); // why is w1 file != w2 file?
w2.Write( arrByte );
w2.Close();
w2.Close();
Objective: store byte array into a string.
Require: the string will be returned to classic ASP, which means that the
content can not be encoded, nor can it be serialized.
Greetings all,
From classic ASP I am accessing C# COM object which is responsible for
network socket communications and returning binary data. The classic ASP is
to take the returned binary data and send it to browser via
Response.BinaryWrite( myBinaryVarient ) to display a PDF document.
In past we did this using VB6 COM objects, where the binary data was stored
in String. However, despite my efforts, I am unable to save binary data into
a string without affecting the data when using C#. Here is a sample code
that demonstrates writing a binary array into a file; and converting the
array into string and then writing it to file. You'll find that the two
files are NOT the same!
Do you have any ideas on this matter...
tnx in advance
// --- Allocate byte array
byte [] arrByte = new byte[255];
for( int i=1; i< arrByte.Length; i++ )
arrByte = (byte)i;
// --- Create two file handlers
string file = "BinaryFile";
FileStream fs1 = new FileStream( file + "1", FileMode.Create );
FileStream fs2 = new FileStream( file + "2", FileMode.Create );
BinaryWriter w1 = new BinaryWriter( fs1 );
BinaryWriter w2 = new BinaryWriter( fs2 );
// --- Econde binary to string
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("iso-8859-1");
string str = enc.GetString( this.arrByte );
// --- Write data to file
w1.Write( str ); // why is w1 file != w2 file?
w2.Write( arrByte );
w2.Close();
w2.Close();