I am using .NET 3.5 ASP.NET. My website currently serves the PDF as follows:
context.Response.WriteFile(@"c:\blah\blah.pdf");
This works great. However, I would like to serve it using a method context.Response.Write(char [], int, int).
So, I tried to send the file through
byte [] byteContent = File.ReadAllBytes(ReportPath);
ASCIIEncoding encoding = new ASCIIEncoding();
char[] charContent = encoding.GetChars(byteContent);
context.Response.Write(charContent, 0, charContent.Length);
This did not work (for example, the plugin in the PDF browser complains that the file is damaged).
So, I tried the Unicode approach:
byte [] byteContent = File.ReadAllBytes(ReportPath);
UnicodeEncoding encoding = new UnicodeEncoding();
char[] charContent = encoding.GetChars(byteContent);
context.Response.Write(charContent, 0, charContent.Length);
which also did not work.
What am I missing?
source
share