How to view an uploded file(pdf,doc,etc) or grab a file from db and show on the same page with some good styling for document if i upload a word file then the content of files should display as they are in the file( color,styling, alignment) with some nice centered aligned div outside it
how can i do this
Jayraj ChhayaRank #304 · 8.2K reputationPosted Feb 19, 2024, 2:46 AM EST
To achieve this functionality in a Dot Net application, you can follow these steps:
By combining these steps with appropriate Dot Net libraries and CSS styling, you can create a seamless experience for users to upload and view files while preserving the original document styling.
Madhu PatelRank #663 · 3.6K reputationPosted Feb 20, 2024, 5:52 AM EST
To achieve the functionality mentioned above, you can follow these steps:
1. Upload File: Create a file upload control in your ASP.NET web form to upload files. Handle the file upload on your server side and save the file in the database.
In demo.aspx
demo.aspx.cs
protected void btnUpload_Click(object sender, EventArgs e) { if (fileUpload.HasFile) { // Save the file to database } }2. Retrieve File and Display: Retrieve the uploaded file from the database. Use appropriate libraries for parsing and rendering different document types (PDF, DOC, etc.).
3. Styling: Use CSS to style the container where you are displaying the document.
.document-container { text-align: center; margin: 20px; }The actual approach may vary depending on the specific requirements as you can save the file in the database as well as on the server also, and you may need to adapt it based on the document types you are handling and your chosen libraries for rendering them.
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 9, 2024, 3:27 PM EST
Implement validation to ensure that only allowed file types and sizes are uploaded. This helps prevent security vulnerabilities and ensures a smooth user experience.
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 9, 2024, 3:27 PM EST
Consider implementing security measures such as authentication and authorization to control access to uploaded files and prevent unauthorized users from viewing or modifying them.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts