473,499 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c#, binarywrite method.

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.
Nov 17 '05 #1
2 6062
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);

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Nik" <nc*****@think3.com> wrote in message
news:69**************************@posting.google.c om...
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.


Nov 17 '05 #2
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);

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Nik" <nc*****@think3.com> wrote in message
news:69**************************@posting.google.c om...
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.


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3772
by: Kevin Humphreys | last post by:
Hi All, Please help me regarding the 'Response.BinaryWrite' I am making one web application where I need to store some of client logo's and others images. In this context I am able to store...
0
336
by: Nik | last post by:
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 =...
2
1234
by: Vinay | last post by:
Hi All: I have a frameset (right and left). In the left frame I have a listbox that contains items. When the user clicks on any one of these items (each item points to either a word document or...
1
2747
by: Alex Nitulescu | last post by:
Hi. I have a WebService which provides a webmethod which returns a byte array representing a picture. The method's signature is: <WebMethod(Description:="Shows something nice every time !")>...
0
1566
by: csgraham74 | last post by:
Hi guys back again with another issue. im trying to develop an application which displays a pdf document using the binary.write method. i have 2 pages A and B what i want to do is to load...
2
8362
by: PrePort | last post by:
The goal here is to return a dynamic image from an HttpHandler that I have written. 2 questions 1. I am reading the images into byte fine and cacheing them fine, but what should I use to deliver...
12
7604
by: Katie | last post by:
Hi, I am doing a binaryWrite to allow users to download files. The problem occurs if the file is too big. Some of the files i have are close to 100 megs. I read on msdn that if the data is...
0
2509
by: S N | last post by:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client. Kindly indicate the maximum size of the file that can be...
14
11869
by: S N | last post by:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client. Kindly indicate the maximum size of the file that can be...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.