protected void btnSubmit_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Session["AgentMasterID"]); string temp = ""; if (fuProducImage.HasFile) { if (CheckFileType() == true) { string ext1 = Path.GetExtension(fuProducImage.FileName); var query = (from c in agb.AgentProducts orderby c.AgentProductID descending select c.AgentProductID).First(); int lastid = Convert.ToInt32(query); int last = lastid + 1; string directoryPath = Server.MapPath("../AgentImages/") + id; string vitualp = directoryPath.Replace(@"C:\Users\NET DEVELOPMENT\Desktop\working\AgentWeb", "~").Replace(@"\", "/"); string filepath = vitualp + "/"; if (!Directory.Exists(filepath)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(filepath + "/")); fuProducImage.SaveAs(HttpContext.Current.Server.MapPath(filepath + "/" + last + ext1)); temp = filepath + last + ext1; } else { fuProducImage.SaveAs(Server.MapPath(filepath + last + ext1)); temp = filepath + last + ext1; } //fuProducImage.SaveAs(MapPath("~/AgentImages/" + fuProducImage.FileName)); } } dmp.Product = txtProduct.Text; dmp.AgentMasterID = Convert.ToInt32(Session["AgentMasterID"]); dmp.Description = txtDescription.Text; dmp.Features = txtFeatures.Text; dmp.ProductMRP = Convert.ToDecimal(txtMRP.Text); dmp.ProductProfit = Convert.ToDecimal(txtProfit.Text); dmp.ProductSellingPrice = Convert.ToDecimal(txtSellingprice.Text); dmp.ProductImage = temp; //if (!IsPostBack) //{ dmp.InsertAgentproduct(); //} lblPimage.Visible = true; lblPimage.Text = "Data Inserted Sucesfully"; displayproduct(); txtProduct.Text = ""; txtProfit.Text = ""; txtMRP.Text = ""; txtFeatures.Text = ""; txtSellingprice.Text = ""; txtDescription.Text = ""; } bool CheckFileType() { string ext1 = Path.GetExtension(fuProducImage.FileName); switch (ext1.ToLower()) { case ".png": return true; case ".jpg": return true; case ".jpeg": return true; default: return false; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)