protected void Simpan_Click(object sender, EventArgs e) { Koneksi cn = new Koneksi(); //Response.Write("<script language='javascript'>window.alert('Harap Pilih File untuk di Upload');</script>"); //get session mem id foreach (string key in Session.Contents) { memid = Session["Member_ID"].ToString(); } if (FileUploadGambar.HasFile) //cek file upload null / tidak { string extension = Path.GetExtension(FileUploadGambar.PostedFile.FileName); Label2.Visible = true; //Label2.Text = "File Sukses TerUpload dengan Nama: " + "Foto_" + nama + "" + extension + " dengan User : "******"User"] + " "; //imgPath string ran = Guid.NewGuid().ToString("n").Substring(0, 8);//get random num string nama = "File" + memid; string imgPath = "../img/" + ran + "_" + nama + extension; //Upload File FileUploadGambar.SaveAs(Server.MapPath(imgPath)); byte[] theImage = new byte[FileUploadGambar.PostedFile.ContentLength]; HttpPostedFile Image = FileUploadGambar.PostedFile; Image.InputStream.Read(theImage, 0, (int)FileUploadGambar.PostedFile.ContentLength); int length = theImage.Length; string fileName = FileUploadGambar.FileName.ToString(); string type = FileUploadGambar.PostedFile.ContentType; int size = FileUploadGambar.PostedFile.ContentLength; if (FileUploadGambar.PostedFile != null && FileUploadGambar.PostedFile.FileName != "") { string Hasil; Hasil = cn.KelasKoneksi_InsertStock(Convert.ToInt32(memid), TxtNamaBarang.Text, TxtTgl.Text, TxtKet.Text, DropDownListStatusBarang.SelectedValue, Convert.ToInt32(TxtJumlah.Text), imgPath); if (Hasil == "OK") { Response.Write("<script language='javascript'>window.alert('Berhasil Menyimpan Data!');window.location='../Halaman/Master.aspx';</script>"); } else { Response.Write("<script language='javascript'>window.alert('Gagal Menyimpan Data dengan Error : " + Hasil + "');window.location='../Halaman/Master.aspx';</script>"); } } } else { Response.Write("<script language='javascript'>window.alert('Harap Pilih File untuk di Upload');</script>"); } //Hasil = cn.KelasKoneksi_InsertStock(); }