Weird C# File to byte array issue

  • Thread starter Thread starter sbxn14
  • Start date Start date
S

sbxn14

Guest
Hey everyone!

I have a weird problem. I am making a C# MVC application which generates PDF's and offers them for download with a download button.

public ActionResult Download()
{
string url = (string)TempData["url"];

byte[] thePdf = System.IO.File.ReadAllBytes(url);

return File(thePdf, "application/pdf");
}


All of a sudden I can't properly convert a PDF file to byte[], either with File.ReadAllBytes() or with a Memorystream (or any other stream).


When I used a Memorystream I got an InvalidOperationException on both the ReadTimeOut and WriteTimeOut.


I implemented the code mentioned above in a new C# MVC Project and there everything worked fine. So the issue must be with the project that i'm working in.


EDIT:

When I read out the bytes, it does return a full byte array but when it is downloaded and converted back to a PDF, the PDF is empty (all pages do exist) and the name is some collection of weird characters.

In the new project, it is just the normal PDF as it should be.


Does anyone have any clue what this might be and how i could fix it?

Continue reading...
 
Back
Top