1
Answer

PDF file that is retrieved from database is incorrect

Good day guys hope you will help me on this,
 
Lately I am saving pdf files in MySQL database into BLOB Datatypes. Few days later
I discover how to retrieve the PDF Files that I saved from the database. But there is a problem,
When I open the pdf file that I retrieve. Error message shows that is in incorrect format and 
it's not a pdf file. Below is my code for retrieving PDF File:
 
 
DataTable table = part.GetPartAttachment();
byte[] filedata = (byte[])table.Rows[0][0];
SaveFileDialog sfd = new SaveFileDialog();
string filetosave;
sfd.Filter = "(*.pdf)|*.pdf";
if (sfd.ShowDialog() != DialogResult.Cancel)
{
filetosave = sfd.FileName;
FileStream fs = new FileStream(filetosave,FileMode.Create,FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(filedata);
bw.Close();
}
 
Hope you'll help me on this masters 
Answers (1)