Last post May 04, 2012 09:00 AM by jozolo
Mar 07, 2007 09:52 AM|maniac|LINK
I had this issue a while back, but didn’t find a solution. When opening pdf stored in SQLSVR from any browser, this error occurs:
“There was an error opening this document. The file is damaged and could not be repaired.”
Doc & rtf work. I’m using ASP.net 2005, framework 2x.
Document is being uploaded via FileUpload & btnClick event to pass
FileType, FileSize, FileContent to business layer/sp. The document is same size locally & in SQLSVR, so I don’t think it’s being truncated.
Download occurs when user clicks hyperlinkfield to view document in any browser. It’s during this time that pdf fails to open.
Any suggestions … ?
Mar 07, 2007 11:29 AM|Haissam|LINK
We need to check your code in order to track it.
please post your code which is handling the file download
Mar 08, 2007 01:52 PM|maniac|LINK
Sorry for not replying sooner. EM notification not working from forum? I will check that shortly.
Thank you in advance for prompt professional reply, as always from this forum. MS ROCKS!!
______default.aspx.vb code (click link, get document)
If Request.QueryString("OrderID") <>
'qs present & no issue
aSplitQS = qsOrderIDControlNum.Split(","c)
aSplitControlNumName = aSplitQS(1).Split("="c)
result = clsOrder.LoadDocument(OrderId) 'sp that retrieves document from SQLSVR
.ContentType = clsOrder.ContentType
.OutputStream.Write(clsOrder.FileData, 0, clsOrder.FileSize)
______Order class LoadDocument method
mOrderID = OrderID
ds = DLLR.DataAccess.ExecuteDataset(Data.CommandType.StoredProcedure,
______ Order class variables
Mar 09, 2007 09:00 AM|maniac|LINK
Any suggestions .... EM is working.
Mar 09, 2007 09:49 AM|maniac|LINK
Adobe diagnostic link
Still researching ...
Mar 09, 2007 11:27 AM|maniac|LINK
Having server checked. Let you know after reconfigured.
Mar 09, 2007 02:39 PM|maniac|LINK
Troubleshot via Adobe's checklist ... no luck
Open IIS Manager, then navigate to APPL.
Right click APPL, properties.
Under HTTP headers, file types, add a new type.
For MIME type dialog box, please enter
For MIME type text box, please enter
Dunno ... must be code issue ...
I believe that Adobe, browser & server have been eliminated as causes.
Mar 09, 2007 02:47 PM|maniac|LINK
Does anybody know if there were a specific way that pdf's must be stored in DB?
Oct 17, 2007 03:16 PMfirstname.lastname@example.org|LINK
I had the same problem
The pdf I imported to database by using openrowset()
May 06, 2008 10:08 AM|fyz|LINK
Jan 03, 2011 05:26 PMemail@example.com|LINK
Its not a code problem. Use Foxit Reader and it will open it. pdf's created in a much older version of Adobe's creator software cannot be opened by 9.x and version 10 in some scenarios. This problem occurs on Windows 7 Pro and Windows XP SP 3.
Mar 09, 2011 02:42 PM|Glade Mellor|LINK
I don't think the error is in your code for downloading the document. I believe the error is happening because of how the document is originally stored in the database. Make sure you aren't using the GetBuffer() method when writing the file to the database.
Try using ToArray() instead and it will not append extra characters to the end of your file stream. Here's a link to give you some more details:
The extra characters after the %%EOF tag at the end of your PDF document are most likely what is causing the message:
Try opening your document in VIM/SlickEdit, etc (something that shows hidden characters) to verify that extra data is getting tacked onto the end of the file (it will just look like a bunch of spaces in notepad). You can also confirm this by checking the
size of the document vs. the size of the data stored in your database field.
I hope this helps.
May 04, 2012 09:00 AM|jozolo|LINK
This is an old post, but it helped me solve my similar problem, so I'm adding my findings to this post in the hopes that it helps someone else.
I encountered this problem as well. Jason's tip to open the document in a text editor helped me get to the bottom of my problem, along with Glade's mentioning of extra characters after the %%EOF. The problem was extra characters after the EOF that were
getting added after my document was being displayed.
Looking at maniac's code, I see the same issue in his code that was causing the problem in my code. There was a Response.End() that both maniac and I had commented out because it was giving a Threading.ThreadAbortException. That Response.End() is required,
or else extra content will be appended to the bottom of the PDF file, causing it to be corrupted on retrieval from the database.
As a side-note, I had tried replacing my Response.End() with a HttpContext.Current.ApplicationInstance.CompleteRequest(), but that was not sufficient to avoid appending the extra content to the PDF.