c#, binarywrite method.

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.
 
D

Dmitriy Lapshin [C# / .NET MVP]

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);
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top