hi every one;
i am beginners in asp.net.
here i have a problem is that:
I have two webfrom in one form i upload images in database. That is uploaded successfully.
in 2nd form i have one image button and one image box. I want that when user click image button then new uploaded image is displayed in image box.
in other words i want to know how to retrieve images from database and display in image box.
please give me some hints as soon as possible;
thanks in advance.
here is my image upload code:
SqlConnection con = new SqlConnection(@"connection string");
SqlCommand com;
photo phobj=new photo();
protected void btnsubmit_Click1(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
String filename = FileUpload1.PostedFile.FileName;
String FileExtension = Path.GetExtension(filename).ToLower();
String[] ExtesionAllowed = { ".png", ".gif" };
if (FileExtension.Contains(Path.GetExtension(filename).ToLower()))
{
try
{
String FileSavePath = Server.MapPath("~/Photos/");
FileUpload1.PostedFile.SaveAs(FileSavePath + FileUpload1.PostedFile.FileName);
}
catch (Exception)
{
lblmsg.Text = "unable to upload.";
}
}
else
{
lblmsg.Text = "File Extension " + Path.GetExtension(filename).ToLower() + " is not allowed";
}
phobj.url = Path.GetFileName(filename);
phobj.alpha = drp_name.SelectedItem.Text.ToString();
phobj.message = txtname.Text;
con.Open();
string query = "Insert Into Images(url,name,message)Values('" + phobj.url + "','" + phobj.alpha + "','" + phobj.message + "')";
com = new SqlCommand(query, con);
if (com.ExecuteNonQuery() > 0)
{
lblmsg.Text = "Images Submited";
}
}
else
{
lblmsg.Text = "Operation Failed...please try again...";
}
con.Close();
}