-7

Say I have a program where a user is presented with a treeview of multiple directories and must check desired file/directories that they would like to later be copied.

That aside once the user has selected the files how can I go about creating a separate executable after a button is clicked that will perform the copy of the selected paths that were chosen in the main/first application?

I hope I've clearly expressed the goal I am trying to achieve, I did not feel this would required me to release my projects current code due to the simplicity of the task.

  • Have a look at TLP, – Olivier Jacot-Descombes Aug 22 '16 at 22:17
  • @OlivierJacot-Descombes: Not sure how that is relevant. – Robert Harvey Aug 22 '16 at 22:22
  • @OliverJacot-Descombes I need a simpler answer im sure from my question you can assume im very inexperienced and any Microsoft page that explains the concept in the most confusing way possible will be little help to me – user3600365 Aug 22 '16 at 22:25
  • 1
    You want the program to make another program which you later run and it does the copy you specified? Maybe it could output a .bat file or powershell script? – Ewan Aug 22 '16 at 22:44
  • What you probably need, is not to create and start another executable but multitasking, i.e. the ability to start another thread copying your files that runs in background. You can do that with BackgroundWorker as well. – Olivier Jacot-Descombes Aug 23 '16 at 12:04
-1

You could use the CodeDom. Maybe something like this:

using System;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
class Program
{
    static void Main(string[] args)
    {
        var csc = new CSharpCodeProvider(new Dictionary<string, string>() {{ “CompilerVersion”, “v4.0” }});
        var parameters = new CompilerParameters(new[] { “mscorlib.dll”, “System.Core.dll” }, “NewProgram.exe”, true);
        parameters.GenerateExecutable = true;
        CompilerResults results = csc.CompileAssemblyFromSource(parameters,
        @”using System.IO;
            class Program {
              public static void Main(string[] args) {
                  File.Copy(""c:\temp\from.txt"",""c:\temp\to.txt"");
              }
            }”);
        results.Errors.Cast<CompilerError>().ToList().ForEach(error => Console.WriteLine(error.ErrorText));
    }
}
  • +1 this answer fits my needs best so far......... could this be modified to grab a list array of paths and corresponding destinations that would be created in the initial application before calling on to this CodeDom..........Thanks for your help – user3600365 Aug 23 '16 at 16:52
  • Why the downvotes, folks? – John Wu Aug 23 '16 at 19:03
  • could you help with what i said in my previous comment? – user3600365 Aug 23 '16 at 19:19
  • 2
    @JohnWu probably because it is answering an off-topic question. Once the question is closed, it and its answers need negative scores for Roomba to handle the question (it is a bit more complicated but that is the short version). – user22815 Aug 25 '16 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.