How to load a javascript file into a c# console application

682 views Asked by At

I am stuck with a problem while trying to run a script which is in a file with .js extension in my project. i am trying to load it and call a function in the js file. the code i am using is as bellow:

ScriptControlClass js = new ScriptControlClass();
js.AllowUI = false;
js.Language = "JScript";
js.Reset();
string sc1 = @File.ReadAllText("SQLProJSQueryFormatter.js");
js.AddCode(@sc1);
object[] parms = new object[] { "SELECT * FROM licenseKeys LIMIT 1000;" };
int result = (int)js.Run("formatQuery", ref parms);
Console.WriteLine(result);

But, I am getting a syntax error, the problem is while I am loading the file using File.ReadAllText then js.AddCode line is giving syntax error, it is not loading javascript code properly (putting \n for newlines). Can somebody help me?

0

There are 0 answers