Friday, October 18, 2013

how to execute and interact VBScript code dynamically in .net

just use ClearScript download (or nuget) clearscript then try this using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.ClearScript; using Microsoft.ClearScript.Windows; public partial class formula_Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { using (var engine = new VBScriptEngine()) { engine.AddHostType("Console", typeof(Console)); engine.Execute("function myfunction(insuredvalue) \n" + "a = 5\n"+ "b = 6\n" + "myfunction = insuredvalue + a + b \n" + "end function"); Response.Write(engine.Script.myfunction(55).ToString()); } } }

Wednesday, October 2, 2013

how to send email with html content and embedded images in .net (c#)

1) Attach the image and give it a content id

var img = new System.Net.Mail.Attachment("x.png");
img.ContentId = "haha";

2) Set the .net mail object to allow html body

mail.IsBodyHtml = true;

3) send your html content like this

<img src="cid:haha" /><br />
that's all.