Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# : How to convert a local pdf file to a byte [][]

Tags:

c#

byte

SITUATION

  • Using C# ASP.NET on VS 2008
  • I want to
    • Read a pdf file from my local directory (What stream type do I use? Can I use filestream?)
    • Put this pdf file into a byte[][] variable

QUESTIONS

  • Being new to C#, I would like suggestion (please explain with code), on how I can achieve this.
  • I need to know this to complete my project. Any other inputs will be appreciated.

The code is as follows


   byte[][] pdfDoc= new byte[1][];
byte[] outputDoc = File.ReadAllBytes(@"d:/test.pdf"); for (int x = 0; x < pdfDoc.Length; x++) { pdfDoc[x] = outputDoc; }

But it is failing, not able to read the file from the d:/test.pdf location. Thanks.

like image 971
user1486403 Avatar asked Dec 10 '25 13:12

user1486403


1 Answers

I think this will work for you:

byte[] bytes = File.ReadAllBytes("c:\\folder\\myfile.pdf");
like image 178
Chris Gessler Avatar answered Dec 13 '25 09:12

Chris Gessler