0

Maybe you didnt understand the title, but my question is : I have an Builder. This builder creates an output (.exe) which uploads my pictures folder to the FTP-Server. I actually want to know how to use the textboxes from the builders form to get the credentials into the source code which is going to compiled?

Builder Form --> TextBox (I will type in the credentials) ----> Input of the TextBox will be used as the log in credentials for the FTP-Server in the source code which is going to be compiled.

How can I do that? If I just say

Temp.AppendLine(@"request.Credentials = new NetworkCredential(textBox7.Text,textBox8.Text);");

I get an Error because the output cant find the textBox...

svick
  • 236,525
  • 50
  • 385
  • 514
GumGun
  • 15
  • 1
  • 1
  • 5

2 Answers2

0

Do you mean to do this?

Temp.AppendLine(string.Format("request.Credentials = new NetworkCredential(@\"{0}\",@\"{1}\");", textBox7.Text, textBox8.Text));
YK1
  • 7,327
  • 1
  • 21
  • 28
  • I want that the user can write his server id, his name, and his password into textboxes from the builder. Then the builder should compile an .exe which logs into the ftp server with the information from the textboxes... – GumGun Jun 14 '13 at 18:35
  • @GumGun: Yeah, i guess that didn't compile for you - i've updated the answer (added quotes around the values). – YK1 Jun 14 '13 at 19:18
  • Thank you very much sir, I will try this out after solving another problem -__- Maybe you can help me ? : If I run this code, i got an error message saying : } expected – GumGun Jun 15 '13 at 16:23
  • 1
    @GumGun: You should ideally post it as different question - but any way you cannot have `Ergebnis` method inside `Main` method. First close the `}` for `Main` and then declare `Ergebnis` method. – YK1 Jun 15 '13 at 16:48
  • Ok thank you sir I already made a new question and it was answered well^^ – GumGun Jun 15 '13 at 18:31
0
        String InputCode = String.Empty;

        InputCode = "MessageBox.Show((1 + 2 + 3).ToString());";

        System.CodeDom.Compiler.CodeDomProvider CodeDomProvider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp");

        System.CodeDom.Compiler.CompilerParameters CompilerParameters = new System.CodeDom.Compiler.CompilerParameters();
        CompilerParameters.ReferencedAssemblies.Add("System.dll");
        CompilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
        CompilerParameters.CompilerOptions += "/target:winexe" + " " + "/win32icon:" + "\"" + textBox6.Text + "\"";
        CompilerParameters.GenerateInMemory = true;


        StringBuilder Temp = new StringBuilder();
        Temp.AppendLine(@"using System;");
        Temp.AppendLine(@"using System.Windows.Forms;");
        Temp.AppendLine(@"namespace RunTimeCompiler{");
        Temp.AppendLine(@"public class Test{");
        Temp.AppendLine(@"public static void Main(){");
        Temp.AppendLine(@"public void Ergebnis(){");

        Temp.AppendLine(InputCode);
        Temp.AppendLine(@"}}}}}");

        System.CodeDom.Compiler.CompilerResults CompilerResults = CodeDomProvider.CompileAssemblyFromSource(CompilerParameters, Temp.ToString());
        //Auf CompilerFehler prüfen
        if (CompilerResults.Errors.Count > 0)
        {
            MessageBox.Show(CompilerResults.Errors[0].ErrorText, "Fehler bei Laufzeitkompilierung", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
GumGun
  • 15
  • 1
  • 1
  • 5