View Single Post
  #1 (permalink)  
Old Sep 20th, 2007, 08:41
hanusoft hanusoft is offline
New Member
Join Date: Sep 2007
Location: gurgaon
Age: 22
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Example of Image Upload

Here we are uploading images in File System and storing path in the database.


Code (ImageUpload.aspx.cs) :-
Code: Select all
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.");
            }
        }

Last edited by karinne; Sep 25th, 2007 at 13:00. Reason: Removed links and no signatures allowed until you reach 10 posts.
Reply With Quote