1.需要添加微软的类库 Interop.MSScriptControl.dll
2.
var path = Path.GetFullPath("../../javascript/youziku.lib.js");
string str2 = File.ReadAllText(path);
string fun = string.Format(@"hex_md5(‘{0}‘)", item.Text);
string result = ExecuteScript(fun, str2);
3.
private string ExecuteScript(string sExpression, string sCode)
{
MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();
scriptControl.UseSafeSubset = true;
scriptControl.Language = "JScript";
scriptControl.AddCode(sCode);
try
{
string str = scriptControl.Eval(sExpression).ToString();
return str;
}
catch (Exception ex)
{
string str = ex.Message;
}
return null;
}