Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to upload PDF, any document file as a binary format to database
and view it into a browser in my MVC application

Please help me any Ideas or any code provide me

Where document file will convert from binary to html view page
Posted

You want to write a HTTP Handler that handles requests that contain the DB id of the object, and returns the bytes of the object, with the right header. This has been covered ad nauseum all over the web, I am certain this site will have articles on it. Did you look ?
 
Share this answer
 
Your can convert pdf file in to byte array By following code

C#
byte[] array = new byte[file.ContentLength];
file.InputStream.Read(array, 0, array.Length);


By following code you can recheck the file

C#
System.IO.File.WriteAllBytes(@"c:\test.pdf", array);


store the byte array to database easily.
and also read the byte array and export as follows ...

C#
Response.Clear(); 
MemoryStream ms = new MemoryStream(pdfBytearray); 
Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf"); 
Response.Buffer = true; 
ms.WriteTo(Response.OutputStream); 
Response.End(); 



Following is the refferance link

http://stackoverflow.com/questions/1324597/how-to-render-an-asp-net-mvc-view-in-pdf-format?rq=1[^]

http://stackoverflow.com/questions/7747796/displaying-pdf-files-in-a-web-page-from-a-sql-database-directly-without-needing[^]

http://www.c-sharpcorner.com/UploadFile/013102/save-and-read-pdf-file-using-sql-server-and-C-Sharp/[^]

Convert a byte array to pdf in c#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900