Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Mohammed Ajaz
Mohammed Ajaz
5,542 Points

Convert an image to binary data. Send it to the server and database, save it and then how to retrieve it using razor.

Hi Guys,

I need help by converting an image to binary data and sending it to the server, saving it to my database using entity and then displaying it on my cshtml file. This is using asp.net. Thank you.

1 Answer

Milad The Computer Guy
Milad The Computer Guy
20,287 Points

if you want to store an image to a database, solution is very simple, you just need to store the path to that image into your DB, not the actual image, for example if the path to your image is img/flower.png, then you need to store it into your database as a varchar 'img/flower.png', the actual image will remain in your hosted server inside img folder. I have had dynamic projects before that I needed to retrieve images from a database and that was achievable by storing the path. hope this helps