Wednesday 11 January 2012

Copy files from source directory to target directory using Xcopy in C#.

If you are interested to copy files and folder to target location using Xcopy then just use the below piece of code to perform you desired operation.
private static void ProcessXcopy(string SolutionDirectory, string TargetDirectory)

{
     // Use ProcessStartInfo class
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "xcopy";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = "\"" + SolutionDirectory + "\"" + " " + "\"" + TargetDirectory + "\"" +          
                                                                                                                                      @" /e /y /I";
    try
    {
         using (Process exeProcess = Process.Start(startInfo))
          {
             exeProcess.WaitForExit();
          }
    }
catch (Exception exp)
    {
         throw exp;
    }
}

Thanks,
Md. jawed

No comments: