Hi!
how to display images in asp.net when i select file upload browse button, that selected image is displayed in control.
which control is used to display images. and also give a code of that process.very urgent sir.
thanku.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 11, 2010, 2:31 AM EST
Following code may help you to upload using Asp.net upload control and show it in a ImageButton control after uploading the image:
protected void btnAddimage_Click(object sender, EventArgs e)
{
string filename = "";
if (FileUpload1.HasFile)
{
try
{
if ((FileUpload1.PostedFile.ContentType == "image/pjpeg") || (FileUpload1.PostedFile.ContentType == "image/jpeg"))
{
filename = FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("~/ContentImages/Profile/Users/") + filename);
Image1.ImageUrl = "~/ContentImages/Profile/Users/" + filename;
}
}
catch (Exception c)
{
}
}
}
Mark it as answer if it helps.
jitendra kumar94 reputationPosted Feb 11, 2010, 9:56 PM EST
ajay rajuRank #4,639 · 333 reputationPosted Feb 12, 2010, 9:36 PM EST
code is not work.
in my image control image is not display. and here what is ("~/ContentImages/Profile/Users/").
plz help me.
thank u.
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 14, 2010, 7:39 PM EST
"~/ContentImages/Profile/Users/" is directory structure i have used in my project
you can say nested directories.