c#, binarywrite method.

  • Thread starter Thread starter Nik
  • Start date Start date
N

Nik

I am trying to write out the equivalent of this asp statement in c#:
Response.BinaryWrite(chrb(239) & chrb(187) & chrb(191)) 'BOM = EF BB BF

string binString = "11111111";
byte myBin = Convert.ToByte(binString);
Response.BinaryWrite(myBin);
binString = "10111011";
myBin = Convert.ToByte(binString);
Response.BinaryWrite(myBin);
binString = "10111111";
myBin = Convert.ToByte(binString);
Response.BinaryWrite(myBin);

I get an error on the binarywrite, the compiler says
Argument '1': cannot convert from 'byte' to 'byte[]'

Any ideas how to do this correctly. I am just trying to write these bytes
so the excel file i write out after this code is recognized as Unicode.

Thanks
Nikhil.
 
Hi,

Safety first: do you produce an XML file that would be read by Excel? As if
you produce a binary one, Excel might not be happy to see this Unicode
prefix.

Then, it seems your way of writing the prefix is overcomplicated. I believe
it's as simple as this:

byte[] BOM = new byte[] {0xef, 0xbb, 0xbf};
Response.BinaryWrite(BOM);
 
Back
Top