In my Windows application, I have a PDF file stored in my database. Problem is, when I try to open the PDF file, I get an error
Adobe Reader could not open 'tem1.pdf' because it is either not a supported file type or because the file has been damaged
But when I open this downloaded PDF normally, it does not give that error. I am getting error when I try to open them through my application.
The code I try to open pdf files which are stored in database is as follows:
private void lstBookParts_SelectedIndexChanged(object sender, EventArgs e)
{
if (lstBookParts.SelectedItems.Count > 0)
{
WiCommonFunction.LoadCommonSettings();
ShowInformation showData = new ShowInformation();
string item = lstBookParts.SelectedItems[0].Text;
string book = bookName;
CalculateCount(book);
DataSet ds1 = showData.ShowBookPDF(item);
DataTable dt1 = ds1.Tables[0];
FileStream FS = null;
var index = lstBookParts.SelectedIndices;
Int32 i = (Int32)(index[0]);
byte[] bytes = (byte[])(dt1.Rows[i]["Content"]);
string filepath = "D:\\temp1.pdf";
FS = new FileStream(filepath, System.IO.FileMode.Create);
FS.Write(bytes, 0, bytes.Length);
FS.Close();
Process proc = new Process();
proc.StartInfo.FileName = filepath;
proc.Start();
}
}By using this code some PDF files get open properly, others are giving error.
How can I solve this problem? Is there any need to make changes in the code?
Please suggest me any solution for this.
Thanks in advance.
Ashwini AgivalePosted Jul 25, 2013, 7:39 AM
I am using devexpress application for storing data.This application is of Digital Library.I do all insertions and updation through this application. And pdf file which I stored in database get opened in devexpress application. Windows application is for user who can only read book,and can see images of books through this application.So the database is same for devexpress and windows application which is sql server 2008.
So what I can do to solve this error.
Iftikar HussainPosted Jul 25, 2013, 6:46 AM
Your code is correct, I think the problem is with the content. Please check weather the file content is proper PDF or not.
How do you save this content initially in your database?
Regards,
Iftikar