2
Answers

replace uploaded in asp.net

Rowshan Ali

Rowshan Ali

11y
955
1
Hello dear
when i upload a file its uploaded.  when i upload another file its uploaded new but not replaced. I want to replace file ,
my trial is bellow.



                



    protected void Button1_Click(object sender, EventArgs e)
    {
        WebService1 con = new WebService1();
        //string icode = Request.QueryString["AssociateID"];
        string icode = Label1.Text;
        if (con.Update_Something("Image", FileUpload1.FileName, "PONO", icode, "POInfo") == "1")
        {
            if (FileUpload1.HasFile)
            {
                FileUpload1.SaveAs(MapPath("~/Web/Images/" + FileUpload1.FileName));
                Response.Redirect("AddPOImage.aspx");
            }
            else
            {
                Label2.Text = "file not receive";
            }
        }
    }
// This avobe code use for upload but not replaced

///My service
// WebService1.cs


    public ConnectionStringSettings product;//web.config
    public DbConnection connection1;//database connection
    public DbCommand cmd1;//command--select,insert............

    [WebMethod]
    public void conn1(string a)
    {
        product = ConfigurationManager.ConnectionStrings["Premier1888bdConnectionString"];//web.config
        connection1 = new SqlConnection();//sql database connection
        connection1.ConnectionString = product.ConnectionString;
        cmd1 = connection1.CreateCommand();
        cmd1.CommandType = CommandType.Text;
        cmd1.CommandText = a;
        connection1.Open();
    }

    [WebMethod]
    public string Update_Something(string UpdateCol, string UpdateVal, string WhereColID, string whereColVal, string table)
    {
        string f = "0";
        try
        {
            conn1(string.Format("update {4} set {0}='{1}' where {2}='{3}'", UpdateCol, UpdateVal, WhereColID, whereColVal, table));
            cmd1.ExecuteNonQuery();
            f = "1";


        }
        catch (Exception ex)
        {
            f = ex.Message;
        }
        return f;

    }



Answers (2)