how to fetch image from DB....

Posted by Ankitsrist under ASP.NET on 1/8/2013 | Points: 10 | Views : 952 | Status : [Member] | Replies : 7
hello,
i have used fileupload control nd inserting image into DB is working correctly....but i m unable to fetch it....nd m confused that which control i have to use to display the image on it except gridview....please suggest




Responses

Posted by: Vforvijay on: 1/8/2013 [Member] Starter | Points: 25

Up
0
Down
Hi...
Refer the below to fetch upload image from database.........
http://www.dotnetcode.in/2011/06/how-to-retrieve-uploaded-images-from.html

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/8/2013 [Member] Starter | Points: 25

Up
0
Down
actualy i need c# code nd i dont want to display in gridview is there not any another way to display the uploaded pic

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemanth.Gottipati on: 1/8/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,Ankitsrist
Try this code....
<asp:Image ID="Logo" runat="server" Width="30" Height="30" />

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dataset ds = "select logo from tbllogos";
Logo.ImageUrl = "../Images/logo/" + ds.Tables[0].Rows[0]["Logo"].ToString();
}
}

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/9/2013 [Member] Starter | Points: 25

Up
0
Down
thanks for ur reply but please tell me sir i am saving my image in DB so how to get this Logo.ImageUrl = "../Images/logo/"...image is not stored in any of my folder

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 1/9/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi Ankitsrist,

Please use image control in asp.net that will help you

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemanth.Gottipati on: 1/9/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Ankitsrist..
Logo.ImageUrl = "../Images/logo/" + ds.Tables[0].Rows[0]["Logo"].ToString();
means u will get image from th db and these image will be stored in project images folder...
if image save is not required just given
Logo.ImageUrl = ds.Tables[0].Rows[0]["Logo"].ToString(); like that....

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/9/2013 [Member] Starter | Points: 25

Up
0
Down
thanks sir following is my cmplete code nd its working fine....but would u please tell me how to store image according to the registered member...means when user login his corresponding pic shud display that he has uploaded....

 private void StartUpLoad() 

{
//get the file name of the posted image
string imgName = FileUpload1.FileName;
//sets the image path
string imgPath = "images/" + imgName;
//get the size in bytes that
int imgSize = FileUpload1.PostedFile.ContentLength;
//validates the posted file before saving
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") {
// 10240 KB means 10MB, You can change the value based on your requirement
if (FileUpload1.PostedFile.ContentLength > 10240)
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);
}
else {
//then save it to the Folder
FileUpload1.SaveAs(Server.MapPath(imgPath));
Image1.ImageUrl = "~/" + imgPath;
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);
}
}

}


Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response