Example of Image Upload

Last post 09-26-2007, 9:28 AM by asdqwed. 1 replies.
Sort Posts: Previous Next
  •  09-20-2007, 5:38 AM Post number 37450

    Example of Image Upload

           Here we are uploading images in File System and storing path in the database.
     
    http://www.hanusoftware.com

    Code (ImageUpload.aspx.cs) :-
    private void Button1_Click(object sender, System.EventArgs e)
            {
        //    Here I am uploading images in Images folder of C drive.
    int intResult=0;
    string strPath = @"c:\Images\"+Path.GetFileName(File1.PostedFile.FileName);
    SqlConnection con = new SqlConnection("server=.;uid=sa;database=pubs;pwd=");
    SqlCommand com = new SqlCommand("Insert into Category(name,imagepath) values(@name,@imagepath)",con);
                com.Parameters.Add("@name",TextBox1.Text);
                com.Parameters.Add("@imagepath",strPath);
                con.Open();
                intResult =  Convert.ToInt32(com.ExecuteNonQuery());
                if(intResult != 0)
                {
                    File1.PostedFile.SaveAs(strPath);
                    Response.Write("Record Inserted.");
                }
            }




    Software Development Company   
  •  09-26-2007, 9:28 AM Post number 37661 in reply to post number 37450

    Re: Example of Image Upload

View as RSS news feed in XML