Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am trying to display binary image in datalist with the use of where clause , in datalist want to show binary image only a particular images of the person who logged in .
I try to do but want be able to show a few images of person who is logged in..
i am using Handler to display images to display images of person who is log in.
in handler which code should i apply not getting , should i used session..
Hop U guyz wil Help Me.
Posted

1 solution

You can extract the binary data from the database of the image, make sure you append the correct format of the file, and then display the file inside the img element. One thing that you should know, is that the file would be in binary form, so you need to write the binary in the form of a file (and appending the file format too),

C#
Response.ContentType = file.MimeType;
Response.BinaryWrite((byte[])file.FileContent);


Above code does that. It sets the content type to the response; file, and then writes the binary data to the response; thus your file.

The article[^] that you should be interested in reading. The article contains all of the code and explaination required for this process. You can add a WHERE clause to extract the files for only the current user id. Such as the following code,

SQL
SELECT * FROM Images WHERE UserId = 2


Or what so ever UserId; might be passed by a parameter.

A very personal tip to you, never ever store your files in the data for a social website. There would be a lot of users storing their files, and the space of the database is very expensive; unless you've bought the SQL Server's Web edition for a space of multiple PBs. Users would upload their data to the server, and the space would be used in the database, instead you should always store the files in the file system, and just store the file's path to the database's table. This would ensure that the database's space is not being used where it should not be used.
 
Share this answer
 
Comments
Aarti Yadav 28-Feb-15 6:53am    
yeah oky, i cant not use SELECT * FROM Images WHERE UserId = 2,
i completed few work i m just stuked to display images of particular person who is online i want to use session like this 'select * from allimage where name ='"+session [sonso]+"'';

hop u understand that what i want to do...
Afzaal Ahmad Zeeshan 28-Feb-15 6:54am    
I do understand that, the code I shared was just an example of extracting the data. You need to send the value as a variable; parameter, like you're doing it. :)

Anyhow, if other is OK for you, then you can also close this thread by marking my post as the answer. :)

Thanks.
Aarti Yadav 28-Feb-15 7:12am    
oky but can u tell me how to do i am trying to show images but cant.. how to work with sesion to use only partivular images
Afzaal Ahmad Zeeshan 28-Feb-15 7:24am    
Do not store images in session variables, they're used for small piece of information, such as userid, username etc. to store the images use the file system, and/or the sessionStorage (HTML5 API).
Aarti Yadav 1-Mar-15 7:26am    
can u help me.....

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