I am saving the pdf file in sqlserver as bytes .When i am trying to retrive and show the file does not shows the content the following error occures
there was an error opening this document the file is damaged and could not be repaired +asp.net
Please any one help me
This is for save
byte[] byteArray = System.IO.File.ReadAllBytes(Server.MapPath("Deal//UI//pdfSample.pdf"));
savetoDB();
Retriving
This is for save
byte[] byteArray = System.IO.File.ReadAllBytes(Server.MapPath("Deal//UI//pdfSample.pdf"));
savetoDB();
Retriving
byte[] document = (byte[])offer.OfferPdf;
//string strExtenstion = ".pdf";
string DocName = "pdfSample";
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=" + DocName + ".pdf");
Response.AddHeader("content-length", document.Length.ToString());
Response.ContentType = "application/pdf";
//Response.TransmitFile("pdfSample.pdf");
Response.BinaryWrite(document);
//Response.Charset = "";
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
//Response.Write(document);
Response.End();


Naresh Babu GopavaramRank #9,687 · 203 reputationPosted Aug 5, 2011, 1:29 AM EDT
Satish BhatRank #2,496 · 563 reputationPosted Aug 5, 2011, 2:24 AM EDT
May be there's issue while saving the file in database and it might got corrupted.
2] What is the datatype and size of the field in SQL server database? is it varbinary(MAX)?
3] try using FileStream
// SAVE TO DATABASE
}
Naresh Babu GopavaramRank #9,687 · 203 reputationPosted Aug 5, 2011, 4:01 AM EDT
I am using the following code for retriving the file,
Naresh Babu GopavaramRank #9,687 · 203 reputationPosted Aug 5, 2011, 4:05 AM EDT
Satish BhatRank #2,496 · 563 reputationPosted Aug 5, 2011, 4:11 AM EDT
As per my understanding, OfferPdf is the property of offer object? Are you using strongly typed dataset or custom business object. In both the cases what is the type of the OfferPdf.
Naresh Babu GopavaramRank #9,687 · 203 reputationPosted Aug 5, 2011, 4:20 AM EDT
Naresh Babu GopavaramRank #9,687 · 203 reputationPosted Aug 5, 2011, 4:25 AM EDT