9 Jul 2017

Retrieving images from SQL Server database without using Path in Asp.net MVC

Retrieving images from SQL Server database without using Path in Asp.net MVC

Guest Post :
I want to retrieve image from the database into asp MVC file.I searched on google everyone has stored relative path in db and they are retrieving that but I want to retrieve the image that is stored in db.I am using razor view engine.

Soluton:
Store your image in binary format and retrieve and deserialize it then. Use that encrypted code on image src with javascript syntax. Your image will be visible.

@{
var base64 = Convert.ToBase64String(item.Photo);
var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
}
<td>
<img src="@imgSrc" /> 
</td>

Users Please post your solution.

No comments:

Post a Comment