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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s