Click here to Skip to main content
15,921,548 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am saving the file content by converting to ToBase64String to my database. The file can be any type like image or excel or word or pdf and so on. Now I would like to view the file upon clicking the view icon. I did some research and found this

https://www.aspsnippets.com/questions/168961/Display-file-preview-in-jQuery-modal-popup-from-database-path-on-ASPNet-GridView-LinkButton-Click-using-C-and-VBNet/

But I couldn't make it as per my requirement. I would like to create a partial view and display the content which was saved to database as ToBase64String and provide a download button so that user can download the file

I am able to download directly using the following code but I would like to make it to a partial view and provide download option there

What I have tried:

public ActionResult Index()
{
   AttachmentRepository attachmentRepository = new AttachmentRepository();
   var result = attachmentRepository.GetDocument("Environment", 1);
   return File(result.AttachmentData, result.AttachmentType, result.AttachmentName);
}
Posted
Updated 6-Nov-21 7:46am
v2

1 solution

You have to convert the Base64 string back to the original file data before you send it back to the browser.

Frankly, why are you even converting it to Base64 representation when databases can store blob data? Converting to Base64 just makes the file larger before you save it to the database.
 
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