asp.net上傳圖片

//添加
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection userConnection = Connection.getConnection();
        SqlCommand userCommand = new SqlCommand("ajax_insertxiangc", userConnection);
        userCommand.CommandType = CommandType.StoredProcedure;//採用存儲過程
        userCommand.Parameters.Add("@user", SqlDbType.VarChar, 50);//存儲過程參數
        userCommand.Parameters["@user"].Value = TextBox1.Text;//給參數賦值
        userCommand.Parameters.Add("@mingc", SqlDbType.VarChar, 50);//存儲過程參數
        userCommand.Parameters["@mingc"].Value = tb_MingC.Text;//給參數賦值
        userCommand.Parameters.Add("@tupian", SqlDbType.VarChar, 100);//存儲過程參數
        userCommand.Parameters["@tupian"].Value = file_TuP.FileName.Trim();//給參數賦值
        userCommand.Connection.Open();//打開連接
        userCommand.ExecuteNonQuery();
        userCommand.Connection.Close();//關閉連接
        HttpPostedFile postedFile = this.file_TuP.PostedFile; //得到要上傳文件
        string fileName;
        fileName = System.IO.Path.GetFileName(postedFile.FileName); //文件名稱
        if (fileName != "")
        {
            //保存文件到文件夾,地址是當前頁面的同一級目錄下的files文件夾中
            postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("~/") + fileName);
        }
        Response.Write("<script>alert('提交成功!')</script>");
        GridView1.DataBind();
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章