will only copy first item in the array c#
<p>Hi I am trying to write a simple program to copy a folder from one soure to many in parallel.
I am learning c# so have been trying to understand and change code examples, as i figured this the best way to learn somthing new.</p>

<p>The example below does not work as it only copies to the first destination in the destinationPaths</p>

<p>The stange thing is i have a simlar method to copy one file to many and this works everytime
have i missing something?? i would be greatful if someone could tell me why this is not working i am guessing that there maybe certain things you can't do in parallel</p>

<p>any advice would be great</p>

<pre><code>public  void CopyMultipleFolder(string sourceFilePath, params string[] destinationPaths)
    {
        if (string.IsNullOrEmpty(sourceFilePath)) MessageBox.Show("A source file must be specified.", "sourceFilePath");
        else
        {

            if (destinationPaths == null || destinationPaths.Length == 0) MessageBox.Show("At least one destination file must be specified.", "destinationPaths");
            else
            {
                try
                {



                    FileIOPermission writeAccess = new FileIOPermission(FileIOPermissionAccess.AllAccess, destinationPaths);
                    foreach (string i in destinationPaths)
                    {
                        writeAccess.AddPathList(FileIOPermissionAccess.Write, i);
                    }

                    writeAccess.Demand();






                    NetworkCredential user = new NetworkCredential();
                    user.UserName = Properties.Settings.Default.username;
                    user.Password = Properties.Settings.Default.password;

                    if (user.Password.Length == 0 || user.UserName.Length == 0)
                    {
                        MessageBox.Show("No Username or password have been entered click username on menu bar to update", "Update Credentials");
                    }
                    else
                    {

                        Parallel.ForEach(destinationPaths, new ParallelOptions(),
                                         destinationPath =&gt;
                                         {


                                             if (sourceFilePath.EndsWith("*"))
                                             {
                                                 int l = sourceFilePath.Length - 4;

                                                 sourceFilePath = sourceFilePath.Remove(l);
                                             }
                                             else
                                             {

                                                 using (new NetworkConnection(destinationPath, user))
                                                 {
                                                     if (Directory.Exists(destinationPath + "\\" + foldername))
                                                     {
                                                         if (destinationPath.EndsWith("\\"))
                                                         {
                                                             DialogResult r = MessageBox.Show("Folder already Exists " + destinationPath + foldername + " Do You Want To overwrite All Files And Sub Folders", "Overwrite?", MessageBoxButtons.YesNo);


                                                             if (r == DialogResult.Yes)
                                                             {
                                                                 PleaseWait.Create();

                                                                 foreach (string dirPath in Directory.GetDirectories(sourceFilePath, "*", SearchOption.AllDirectories))
                                                                     Directory.CreateDirectory(dirPath.Replace(sourceFilePath, destinationPath + "\\" + foldername));


                                                                 foreach (string newPath in Directory.GetFiles(sourceFilePath, "*.*", SearchOption.AllDirectories))
                                                                     File.Copy(newPath, newPath.Replace(sourceFilePath, destinationPath+ "\\" + foldername), true);


                                                                 list = list + destinationPath + foldername + Environment.NewLine;
                                                             }
                                                             else
                                                             {
                                                             }

                                                         }
                                                         else
                                                         {


                                                             DialogResult r = MessageBox.Show("Folder already Exists " + destinationPath + "\\" + foldername + " Do you Want to overwrite All Files And SubFolders", "Overwrite?", MessageBoxButtons.YesNo);

                                                             if (r == DialogResult.Yes)
                                                             {
                                                                 PleaseWait.Create();

                                                                 foreach (string dirPath in Directory.GetDirectories(sourceFilePath, "*", SearchOption.AllDirectories))
                                                                     Directory.CreateDirectory(dirPath.Replace(sourceFilePath, destinationPath + "\\" + foldername));

                                                                 //Copy all the files
                                                                 foreach (string newPath in Directory.GetFiles(sourceFilePath, "*.*", SearchOption.AllDirectories))
                                                                     File.Copy(newPath, newPath.Replace(sourceFilePath, destinationPath + "\\" + foldername), true);


                                                                 list = list + destinationPath + "\\" + foldername + Environment.NewLine;
                                                             }
                                                             else
                                                             {
                                                             }
                                                         }
                                                     }
                                                     else
                                                     {
                                                         PleaseWait.Create();

                                                         foreach (string dirPath in Directory.GetDirectories(sourceFilePath, "*", SearchOption.AllDirectories))
                                                             Directory.CreateDirectory(dirPath.Replace(sourceFilePath, destinationPath + "\\" + foldername));

                                                         //Copy all the files
                                                         foreach (string newPath in Directory.GetFiles(sourceFilePath, "*.*", SearchOption.AllDirectories))
                                                             File.Copy(newPath, newPath.Replace(sourceFilePath, destinationPath + "\\" + foldername), true);


                                                         list = list + destinationPath +"\\"+foldername+ Environment.NewLine;
                                                     }
                                                 }



                                             }
                                             PleaseWait.Destroy();
                                         });


                        MessageBox.Show("Folder Has Been Copied to " + list, "Folder Copied");
                    }
                }

                catch (UnauthorizedAccessException uae)
                {
                    MessageBox.Show(uae.ToString());
                }



            }
        }
    }
</code></pre>
