Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to load byte array of pdf from MySQL database to my winforms application using this third library called "Apitron.PDF.Controls" but to no avail.

if(_readBytes.Read()) { 
                var getPdfValues = (byte[])_readBytes["PDF_BYTES"];
                String base64 = Convert.ToBase64String(getPdfValues);

                FileStream _FileStream = new FileStream(base64,FileMode.Open);
                pdfViewer1.Document = new Document(_FileStream);
            }
            _readBytes.Close();


The screen throws an exception "The specified path, file anme or both are too long. The fully qualified file name must be less than 260 characters ..."

What I have tried:

This is how the byte array was sent to the DB


Byte[] readPdfBytes = File.ReadAllBytes(open.FileName);
Posted
Updated 5-Dec-22 3:02am
Comments
BillWoodruff 6-Dec-22 6:32am    
look for support or information from "Apitron.PDF.Controls."

how do you know a byte array contains intelligible text ?
Dan Sep2022 6-Dec-22 6:33am    
I just re-read my own code and apparently I was wrong thinking the byte array was a file path.
BillWoodruff 6-Dec-22 6:53am    
everyone here learns through mistakes, and incorrect assumptions. :) cheers, bill

1 solution

The first parameter of FileStream is a path to a file on the file system; not a base64-encoded string. If you already have the byte array for the file then you don't need to use a FileStream, but you could instead use a MemoryStream Class (System.IO) | Microsoft Learn[^]

Simple creating the MemoryStream instance, write the byte array, reset the position back to the beginning and pass it into the Document constructor. If the Document constructor does not take a Stream class then you might need to come up with a work-around.
 
Share this answer
 
Comments
Dan Sep2022 7-Dec-22 2:11am    
Thank you so much sir.. I've been working on this for 4 days and finally it works, I couldn't have done it without your help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900