Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
3.40/5 (3 votes)
I have a database in which I am storing path of the image as varchar. Now in my page I want to put the path of the image in Image source.
Posted
Comments
[no name] 23-Sep-13 7:56am    
Okay so go right ahead and do that. You have my permission to proceed.
Eduard Keilholz 23-Sep-13 8:35am    
Are you voting all questions down? Makes no sense... This question is easy to understand. It would have been nice if the poster added a piece of code of what he tried already, but I see no reason to vote this question down.
[no name] 23-Sep-13 8:44am    
What makes you think for even a single instant that I am voting all question down? What "question" is it that you are referring to? There is no question here. You should verify your facts before jumping to conclusions.
Eduard Keilholz 23-Sep-13 8:51am    
I didn't bring anything as a fact. As you can see my first sentence starts with a question. Furthermore I've seen a couple of questions with only off topic comment. Telling posters they're stupid doesn't help them. Telling them how to improve they're questions does!
Kirill NoNick 23-Sep-13 9:33am    
troll? :P

1 solution

Answer to this question can be pretty complicated, because it depends on where your images repository sits. If the images are within the scope of your website it's wise to store a relative path to the image in your database as well and just render that relative path in a tag

HTML
<img src="/Relative/DbPath.jpg" />


If your images are outside the scope of your website, you need to make sure that the folder the images are in, is readable to IIS. You can then open the image as a binary file and pass is through. This also depends on the type of ASP website you have, if you're using MVC it's even more easy, else you may want to add an ashx file to your project hand handle the image processing from there.

Your images will look like
HTML
<img src="/Image.ashx?databaseId=2" />


image.ashx must then open the actual file (fetch the path from the database and open the file with a stream and then pass the stream to the response object. Make sure you set the response type to the type of image you're about to pass.
Eduard
 
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