While developing a web page that displays PDF, I am having trouble reading a PDF test file, of 86037 bytes, into a char[] array. That array is needed for output in HttpResponse.Write(char[], 0, nrbytes) . My code works fine with HttpResponse.WriteFile(filename), so all http headers must be OK.
When I try:
byte[] bytPdf = File.ReadAllBytes(FileName);
string strPdf = System.Text.Encoding.ASCII.GetString(bytPdf);
char[] chrPdf = strPdf.ToCharArray();
response.Write(chrPdf , 0 , chrPdf.Length);//L=86027, OK
the browser shows two empty pages: two is correct, but the pdf has filled pages. When I try:
string strPdf = File.ReadAllText(FileName);
response.Write(strPdf.ToCharArray(), 0, strPdf.Length);//L=85387, wrong
the string is missing bytes, probably because of some binary bytes mistaken for end-of-file. The browser keeps waiting for data.
I feel that I am not getting the entire PDF content correctly in the string or char[].
Alternatively, is there a method to send a byte[] to the HTTP output, instead of char[]?