image upload

Posted by Amansandha under ASP.NET on 1/18/2009 | Views : 2034 | Status : [Member] | Replies : 2
sir i am aman

and working on real estate project, but i had problem to upload the images of property to database of sql server 2000. someone can help me then pl send me the solution how to upload and retirve the images on aspx page with c#


thnx
with regads
Amansandha




Responses

Posted by: SheoNarayan on: 1/19/2009 [Administrator] HonoraryPlatinum

Up
0
Down
Please visit following link for your solution

http://www.worldofasp.net/tut/UserPhoto/Upload_and_retrieve_image_to_and_from_database_179.aspx

http://aspalliance.com/articleviewer.aspx?aid=140

List of many such articles is here
http://www.dot-net-search.com/how+to+upload+image+in+database+using+ASP.net+and+C%23/

Hope you will get answers in the first link iteself.

Thanks
Take Care.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Posted by: Syedshakeer on: 2/5/2009 [Member] Starter

Up
0
Down
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
public partial class UploadImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1 .Text ="click me";

}
protected void Button1_Click(object sender, EventArgs e)
{



if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{

byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(myimage, 0, (int)FileUpload1.PostedFile.ContentLength);

SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connection"].ToString());
myConnection.Open();
SqlCommand storeimage = new SqlCommand("INSERT INTO guest.Photos"
+ "(Picture) "
+ " values ( @Picture)", myConnection);

storeimage.Parameters.Add("@Picture", SqlDbType.Image, myimage.Length).Value = myimage;

storeimage.Parameters["@Picture"].Value = myimage;

storeimage.ExecuteNonQuery();

Button1.Text = "image inserted sucessfully";
}
}
}


Syed Shakeer Hussain

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

Login to post response