public void Insertproduct() { string filename = ImgFileUpload.PostedFile.FileName; ImgFileUpload.SaveAs(Server.MapPath("~/Product Image/" + filename)); Object productsave = new Object(); productsave.Category_Id = int.Parse(ddlcategory.SelectedValue); productsave.Product_Name = TxtName.Text; productsave.Product_Image = "~/Product Image/" + filename; productsave.Product_Description = TxtDescription.Text; productsave.Product_Quantity = DdlQuantity.SelectedValue; productsave.Product_Price = int.Parse(TxtPrice.Text); productsave.Product_Brand = TxtBrand.Text; productsave.Created_Date = HiddenDate.Value; BSLAYER.saveproduct(productsave); }
//protected void ImgFileUpload_DataBinding(object sender, EventArgs e) //{ // if (ImgFileUpload.HasFile) // { // ImgFileUpload.SaveAs(Server.MapPath("images//" + ImgFileUpload.FileName)); // Label2.Text = "Image Uploaded"; // Label2.ForeColor = System.Drawing.Color.ForestGreen; // } // else // { // Label2.Text = "Please Select your file"; // Label2.ForeColor = System.Drawing.Color.Red; // } //} protected void btnUpload_Click(object sender, EventArgs e) { string folderPath = Server.MapPath("Test/Images/Thanks Card (Without Name).png"); //Check whether Directory (Folder) exists. if (!Directory.Exists(folderPath)) { //If Directory (Folder) does not exists Create it. Directory.CreateDirectory(folderPath); } //Save the File to the Directory (Folder). ImgFileUpload.SaveAs(folderPath + Path.GetFileName(ImgFileUpload.FileName)); //Label2.Text = ImgFileUpload.FileName; //Display the Picture in Image control. imgCard.ImageUrl = "Test/Images/Thanks Card (Without Name).png" + Path.GetFileName(ImgFileUpload.FileName); Label2.Text = "Test/Images/Thanks Card (Without Name).png" + Path.GetFileName(ImgFileUpload.FileName); }
protected void BtnSubmit_Click(object sender, EventArgs e) { Label_Grid1_State.Text = "默认数据源"; Boolean fileOk = false; DataSet ds = upload.S_TemplatUpload_Name(txt_Tmp.Text); DataTable dt = ds.Tables[0]; DataView dv = ds.Tables[0].DefaultView; if (dt.Rows.Count != 0) { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('系统中已有该模板名称,不能重名!')", true); return; } if (txt_Tmp.Text != "") { if (this.ImgFileUpload.HasFile) { //取得文件的扩展名,并转换成小写 string fileExtension = Path.GetExtension(ImgFileUpload.FileName).ToLower(); //验证上传文件是否图片格式 fileOk = IsImage(fileExtension); if (fileOk) { //对上传文件的大小进行检测,限定文件最大不超过8M if (ImgFileUpload.PostedFile.ContentLength < 8192000) { string filepath = "/TemplateUpload/"; if (Directory.Exists(Server.MapPath(filepath)) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(Server.MapPath(filepath)); } string virpath = filepath + ImgFileUpload.FileName; string mappath = Server.MapPath(virpath); System.IO.FileInfo fi = new System.IO.FileInfo(mappath); if (fi.Exists) { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('存在同名文件,请修改后上传!')", true); return; } ImgFileUpload.SaveAs(mappath); tempInfo.TmpUpload_Name = txt_Tmp.Text.Trim(); tempInfo.TmpUpload_ImgUrl = virpath; tempInfo.TmpUpload_Person = Session["UserName"].ToString(); tempInfo.TmpUpload_Time = DateTime.Now; upload.I_TemplatUpload(tempInfo); GridView1.DataSource = upload.SList_TemplateUpload(); GridView1.DataBind(); txt_Tmp.Text = ""; UpdatePanel_Temp.Update(); ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", "alert('模板新增成功!')", true); PanelAdd.Visible = false; UpdatePanel1.Update(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('文件大小超出8M!请重新选择!')", true); return; } } else { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('上传文件类型有误!')", true); return; } } else { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('没有上传文件!')", true); return; } } else { ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "alert", "alert('模板名称不能为空!')", true); return; } }