Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am having one doubt in my application. I am using textarea control in my aspx page. in that control i am having c# program. My requirement is i need to compile that entire code if button was clicked & if any errors are occurred need to show them in another textbox/lable. actually i tried for Windows Form application its working fine now i need it in web application.. here is the code i used for Windows Form application...
C#
public Form1()
{
    InitializeComponent();
    this.button1.Click += new System.EventHandler(this.button1_Click);
   
}

private void button1_Click(object sender, System.EventArgs e)
{
    CSharpCodeProvider codeProvider = new CSharpCodeProvider();
    ICodeCompiler icc = codeProvider.CreateCompiler();
    string Output = "Out.exe";
    Button ButtonObject = (Button)sender;

    textBox2.Text = "";
    System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
    //Make sure we generate an EXE, not a DLL
    parameters.GenerateExecutable = true;
    parameters.OutputAssembly = Output;
    CompilerResults results = icc.CompileAssemblyFromSource(parameters, textBox1.Text);

    if (results.Errors.Count > 0)
    {
        textBox2.ForeColor = Color.Red;
        foreach (CompilerError CompErr in results.Errors)
        {
            textBox2.Text = textBox2.Text +
                        "Line number " + CompErr.Line +
                        ", Error Number: " + CompErr.ErrorNumber +
                        ", '" + CompErr.ErrorText + ";" +
                        Environment.NewLine + Environment.NewLine;
        }
    }
    else
    {
        //Successful Compile
        textBox2.ForeColor = Color.Blue;
        textBox2.Text = "Success!";
        //If we clicked run then launch our EXE
        if (ButtonObject.Text == "Run") Process.Start(Output);
    }
}

Kindly suggest me what i need to do in this case. Send me any references.

I would be thankful.

Thanks in Advance.

What I have tried:

I tried to use existing packages but not working
Posted
Updated 7-Jan-20 10:16am
v4
Comments
Krunal Rohit 26-Feb-14 0:14am    
This is a form application code.
-KR
Sergey Alexandrovich Kryukov 26-Feb-14 0:29am    
Not clear what your problem might be...
—SA
Divyay208 26-Feb-14 0:43am    
sorry in above question i tried for windows form application..but my requirement is for web application i need same implementation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900