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.
-
7It'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.Jon Skeet– Jon Skeet2010-09-24 10:44:14 +00:00Commented 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?Tony Abrams– Tony Abrams2010-09-24 12:16:00 +00:00Commented Sep 24, 2010 at 12:16
-
what does "building a web site" have to do with winforms? How are winforms involved at all!?Kirk Woll– Kirk Woll2010-09-24 14:10:31 +00:00Commented 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.Peter Lillevold– Peter Lillevold2010-09-27 18:27:41 +00:00Commented Sep 27, 2010 at 18:27
Add a comment
|
2 Answers
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.
Comments
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