0

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?

Nmk
  • 1,281
  • 2
  • 14
  • 25
  • What is `ScriptControlClass`? And what is the exact syntax error? You also need to include a [mcve]. Take a look at the [help] and read [ask]. – Herohtar Mar 18 '20 at 18:18
  • ScriptControlClass is from MSScriptControl library, here are my javascript files: – Sepehr baghi Mar 18 '20 at 19:19
  • https://easyupload.io/3eb72t - https://easyupload.io/ka9dzi – Sepehr baghi Mar 18 '20 at 19:19
  • I don't think the @ symbol is needed. Are you sure it's replacing newlines? Debugger might 'show' \n but it not actually be backslash+n. One other thing to consider is your attached file uses unix newlines not windows newlines, so doing c# on windows may not result in the expected newline output. – Charlie Mar 18 '20 at 20:05
  • Thank you for your reply, i found out that it is not about lines problem, the problem is in js files but i can find any syntax error there – Sepehr baghi Mar 18 '20 at 20:28

0 Answers0