this is the code given to me:
protected void btnAdd_Click(object sender, EventArgs e) { divTempForm.Visible = true; rptMailTemplate.Visible = false; mMailTemplate mail = new mMailTemplate(); mail.MailTempleteCode = txtMailTempCode.Text; mail.Subject = txtMailSubject.Text; mail.InsertedBy = _objUserIdentity.UserID; mail.Body = hdsummernote.Value; mail.MailBodyType = ddlMailBodyType.SelectedValue; //mail.Active = lblActive.Text; mail.Active = "Y"; DataSet ds = mtc.InsertMailTemplate(mail); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["out_msg"].ToString() == "RecordAdded") { if (fuImg.HasFile) { fuImg.SaveAs(Server.MapPath("~/MailerImages/" + ds.Tables[0].Rows[0]["MailTemplateID"] + "_" + fuImg.FileName)); **mail.BodyImagePath = @"MailerImages" + ds.Tables[0].Rows[0]["MailTemplateID"] + "_" + fuImg.FileName;** } } } Response.Redirect("MotivationUI.aspx"); }
Basically what this code does is add the values from textbox into sql server. But i need help at mail.BodyImagePath. The text creates a URL for the location of image stored on the server and i need to store that “URL” into the sql table. Any idea how i should do it?
Advertisement
Answer
Just save the image path in string variable within the if condition and update it using your sql query:
string path = @"MailerImages" + ds.Tables[0].Rows[0]["MailTemplateID"] + "_" + fuImg.FileName; Update table set columnName = path where //your condition here;
Note: Do that before Response.Redirect("MotivationUI.aspx");
or within your if condition after assigning path to variable.