views:

104

answers:

2

This question is in follow up to this one: write binary data using JavaScript on the server.

The problem there with just using Response.Write to write the string is that the string contains a null character which JavaScript recognizes as the end of the string.

The string I'm trying to write starts with the following (written here in character codes)

255 216 255 212 0 16 ...

JavaScript will only output the first 4 characters here, because it recognizes the 5th as a string terminator. Is there any way around this?


I should note that I really do have to write out the binary null... the output of this is pdf, so I can't change the output format.

A: 

What about base-64 encoding the data? You'll need to decode it of course.

Raymond W
A: 

You should be able to pass a null object directly into the Write function and have it output the same as an empty string, there should be no runtime errors. Thusly the following code will return nothing to the screen:

protected void Page_Load(object sender, EventArgs e)
{
    string str = null;
    Response.ContentType = "text/plain";
    Response.Write(str);
    Response.End();
}
Ambrosia