2
Answers

i upload the photo in asp.net but i am getting the error

narasiman rao

narasiman rao

12y
1.3k
1
i upload the photo in asp.net but i am getting the error as Could not find a part of the path

Design as follows

 name textbox

address textbox

image fileupload

code as follows

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con;
    string s1;
    string path;
    //SqlConnection con = new SqlConnection();
    SqlCommand com = new SqlCommand();
    SqlDataAdapter da;
    DataTable dt;
    int id;
    string name;
    string address;
    string image;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }
    private void bindgrid()
    {
        con = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
        con.Open();
        da = new SqlDataAdapter("select * from photo", con);
        dt = new DataTable();
        da.Fill(dt);
        da.Dispose();
        //GridView1.DataSource = dt;
        //GridView1.DataBind();
        con.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        con = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
   
        if (FileUpload1.PostedFile.ContentLength > 0)
        {
            s1 = Path.GetFileName(FileUpload1.FileName);
            path = Server.MapPath("images") + "/" + s1;
            FileUpload1.SaveAs(path);
        }
        con.Open();
        SqlCommand com = new SqlCommand("insert_employee", con);
        com.CommandType = CommandType.StoredProcedure;
        com.Connection = con;
        com.Parameters.AddWithValue("@name", txt_name.Text);
        com.Parameters.AddWithValue("@address", txt_Address.Text);
        com.Parameters.AddWithValue("@image", s1);
        com.ExecuteNonQuery();
        bindgrid();
        con.Close();
    }
}


please help me.what is the error and reply me.


Answers (2)