Saving file into database as binary
-
Hi, I am saving pdf file into database reading from memroystream and it is saving properly, but when i try to retreive it it is throwing an error message "ile is damaged and could not be repaired". I am using itextsharp to generate the PDF, as this is urgent appreciate help. Thanks in advance.
ashish
-
Hi, I am saving pdf file into database reading from memroystream and it is saving properly, but when i try to retreive it it is throwing an error message "ile is damaged and could not be repaired". I am using itextsharp to generate the PDF, as this is urgent appreciate help. Thanks in advance.
ashish
Hi, without viewing at your code, it is difficult to decide where the problem is. I'm doing the same thing with itextsharp and a mysql db in some project. Here is how i basically do it:
// Open ITextSharp Document and memstream
Document myDocument = new Document(PageSize.A4);MemoryStream mstream = new MemoryStream();
PdfWriter.GetInstance(myDocument, mstream );
myDocument.Open();
// Do some itextsharp stuff to myDocument
// Close Document
myDocument.Close();// Save stream to byte[] and save that byte[] to your db
byte[] fileData = mstream.GetBuffer();// ...database-saving-logic....
As you're posting this in the asp.net forum, i suppose you want to write this pdf to your reponse stream? (or to file?!) This is how i write it to response-stream in page-load of a download page (you have to replace mimeType, fileName, fileSize and fileData by your own variables/strings - with fileData being the byte[] and filesize the length of that byte[]):
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = mimeType; // (guess it's "application/pdf")Response.AppendHeader("content-disposition", "attachment; filename=" +
HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AppendHeader("content-length", fileSize.ToString());
Response.BinaryWrite(fileData);
Response.End();Hope this helps. If you've problems writing/reading this data from/to a file, let me know.