Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I'm just a beginner. I'm trying to write about the 'Online Book Library' project.
I know how to user FileUpload button.But I want to know how to read ebooks on Browsers and I also want to know how to download the ebooks ( I mean how to use download button) . Thank You.
Posted

First I would like to talk about downloading the files, in ASP.NET, you can use this following code to let the client download the file.

C#
// Provided you wanted to share the name in the QueryString
var file = Server.MapPath("~/documents/" + Request["doc"]);
Response.AppendHeader("content-disposition", "attachment; filename=" + Request["doc"]);
Response.ContentType = "application/octet-stream";
// Transmit file
Response.TransmitFile(file);


Then, for viewing the file content there are a lot of methods, if the file is PDF, then you would need to use some PDF reader, if the file is Word document then a Word reader. There are quite a lot of .NET libraries by third-party developers to let you read the content of these files and write them on the screen as simple pain text (but with styles). One of such libraries is iTextSharp[^]. There are similar more libraries to let you view the content of files. If you would use iTextSharp, then the following links would help you out.

http://stackoverflow.com/questions/2550796/reading-pdf-content-with-itextsharp-dll-in-vb-net-or-c-sharp[^]
http://www.schiffhauer.com/read-text-in-a-pdf-in-c-with-itextsharp/[^]
https://social.msdn.microsoft.com/forums/vstudio/en-US/420e524e-9e2a-4a0a-969d-42284f523f07/read-pdf-using-itextsharp[^]

There are a lot of other libraries and solution out there. Do remember to Google for them when you need them. :)
 
Share this answer
 
Comments
Mario Z 16-Mar-15 5:37am    
I'm not sure but it seems to me that by "reading ebooks on Browsers" he was referring to just viewing them. In that case he doesn't have to use iTextSharp because all the modern browsers support reading and rendering PDF content so he can just redirect the user to a required PDF file.
But for some other eBook formats (like .epub, .ibooks, etc.) the above is applied (google some library that can process the required format).
Afzaal Ahmad Zeeshan 16-Mar-15 6:41am    
You're right, modern day browser are powerful enough to preview the documents and resources when sent down to browser; through drag-n-drop or through HTML. But for a consistent user-interface they are not good choices to be made.

For a consistent user-interface, you should try to provide as much theme as you can, and once you cannot do a thing... You can then get help from software; web browser in this case. Using different software to create one software is not a good choice or good user-experience of user-interface; you can think of them as separate identities. These libraries do the same thing, as that browser would. The plus point that these libraries have is that they allow you to add some custom style themes to your application too.

After all, if you have to let the user be redirected to a resource location, then it is better to just let him download the file and preview the file in his favorite reader; Adobe Reader, or directly inside the browser himself.

Does this now make some sense? :-)
Mario Z 16-Mar-15 9:13am    
Well I would agree with you, but if you are focused on preserving the user-interface consistency that I believe you have suggested a wrong library, iTextSharp does not completely do what browsers do.
You see in order to achieve this he would need to convert a PDF content into a HTML content and iTextSharp cannot do this out of the box (sidenote: it can achieve vice verse, HTML to PDF, but even that is not one of the strong points of this component).
So with iTextSharp he would need to read the PDF graphics and convert each of them to an appropriate HTML element.
Your answer lacks this explanation and the provided resources do not address this task.
Also this is certainly not a trivial task and I wouldn't suggest it to any beginner.

Nevertheless the suggestion that I mentioned does not require over-engineering and it will accomplish the requirements.
Also in case you want to have more control over the PDF presentation you can use "iframe" elements to host the PDF viewer inside your own interface.
Here Is an Article Read It[^]
 
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