Example of Image Upload

Discussion in 'ASP.NET' started by hanusoft, Sep 20, 2007.

  1. hanusoft

    hanusoft New Member

    Joined:
    Sep 3, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Here we are uploading images in File System and storing path in the database.

    Code (ImageUpload.aspx.cs) :-
    Code:
    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 a moderator: Sep 20, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    So whats your query or its just you want to spam forums with the links to your site.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice