-2

i have the js file how can i add that in winform C#, i have developed the front-end and i want to run the js file on button click. i will be thankful to u if u provide the snippet!!!!! I want to run javascript code in windows form thank you.

4
  • 7
    It's not at all clear what's going on here, in terms of ASP.NET and Windows Forms being involved at the same time. Please give a lot more detail. Commented Sep 24, 2010 at 10:44
  • What are you trying to do with javascript that is causing you to want to run it from a winform? Commented Sep 24, 2010 at 12:16
  • what does "building a web site" have to do with winforms? How are winforms involved at all!? Commented Sep 24, 2010 at 14:10
  • you need to provide more detail and context to your question. Validation in WinForms using javascript?? No. Sounds more and more like you're building a WebForms app, in which client-side validation using javascript is commonly used. Commented Sep 27, 2010 at 18:27

2 Answers 2

1

As others have stated here, you should clarify your scenario. That said, this question have an answer to how to run javascript from a .Net application.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use cscript.exe to execute JScript on windows & can capture the output from the stdout.

string output;
using (Process cscript = new Process())
{
    // prepare the process
    cscript.StartInfo.UseShellExecute = false;
    cscript.StartInfo.CreateNoWindow = true;
    cscript.StartInfo.RedirectStandardInput = false;
    // RedirectStandardOutput should be True to get output using the StandardOutput property
    cscript.StartInfo.RedirectStandardOutput = true;
    cscript.StartInfo.FileName = "cscript.exe";
    cscript.StartInfo.Arguments = "<Path to your .js file>";

    cscript.Start();
    output = cscript.StandardOutput.ReadToEnd();
    cscript.Close();
}

Obviously your JScript cannot contain any statement that is illegal on windows

for example when you run JS in a browser it contains the window object. There would be no window object when you run JS in shell using cscript.exe

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.