Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:12:33+00:00 2026-06-11T14:12:33+00:00

While copying around 50 GB of data via local LAN share, due to connectivity

  • 0

While copying around 50 GB of data via local LAN share, due to connectivity issue copy failed at around 10 GB copied.

I have renamed copied 10GB of data directory to localRepository and then written a C# program to copy files from the remote server to destination, only if it is not found in local repository. If found move file from local repository to destination folder.

Although the code worked fine and accomplishes the task very well. I wonder, have I written the most efficient code? Can you find any improvements?

string destinationFolder = @"C:\DataFolder";
        string remoteRepository = @"\\RemoteComputer\DataFolder";
        string localRepository = @"\\LocalComputer\LocalRepository";

        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (string remoteSrcFile in Directory.EnumerateFiles(remoteRepository, "*.*", SearchOption.AllDirectories))
            {
                bool foundInLocalRepo = false; ;
                foreach (var localSrcFile in Directory.EnumerateFiles(localRepository, "*.*", SearchOption.AllDirectories))
                {

                    if (Path.GetFileName(remoteSrcFile).Equals(Path.GetFileName(localSrcFile)))
                    {
                        FileInfo localFile = new FileInfo(localSrcFile);
                        FileInfo remoteFile = new FileInfo(remoteSrcFile);

                        //copy this file from local repository
                        if (localFile.Length == remoteFile.Length)
                        {
                            try
                            {
                                File.Move(localSrcFile, PrepareDestinationPath(remoteSrcFile));
                                Debug.WriteLine(remoteSrcFile + " moved from local repo");
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(remoteSrcFile + " did not move");
                            }
                            foundInLocalRepo = true;
                            break;
                        }
                    }
                }
                if (!foundInLocalRepo)
                {
                    //copy this file from remote repository
                    try
                    {
                        File.Copy(remoteSrcFile, PrepareDestinationPath(remoteSrcFile), false);
                        Debug.WriteLine(remoteSrcFile + " copied from remote repo");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(remoteSrcFile + " did not copy");
                    }

                }
            }
        }

        private string PrepareDestinationPath(string remoteSrcFile)
        {
            string relativePath = remoteSrcFile.Split(new string[] { "DataFolder" }, StringSplitOptions.None)[1];
            string copyPath = Path.GetFullPath(destinationFolder + relativePath);
            Directory.CreateDirectory(Path.GetDirectoryName(copyPath));
            return copyPath;
        }

EDIT:

Based on answer given by Thomas I am attempting to zip the file.
Traditionally as an end user we use to zip a file and then copy. As a programmer can we zip and copy the file parallel? I mean the portion which has been zipped send it over the wire?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:12:34+00:00Added an answer on June 11, 2026 at 2:12 pm

    You are doing far too much work with the nested loop.

    You should remove the inner “foreach” and replace it with some code that:

    (1) Constructs the name of the file that you are looking for and

    (2) Uses File.Exists() to see if exists, then

    (3) Continues with the same block of code that you currently have following the “if (Path.GetFileName(remoteSrcFile)…” condition.

    Something like this:

    foreach (string remoteSrcFile in Directory.EnumerateFiles(remoteRepository, "*.*", SearchOption.AllDirectories))
    {
        string localSrcFile = Path.Combine(localRepository, Path.GetFileName(remoteSrcFile));
    
        if (File.Exists(localSrcFile))
        {
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to copy data from DB source to db destination should the copying
Hej, I have some data shipped out with the app which shall be copied
I have copied contacts local phonebook and have shown them in my custom list.
Does the File.Copy(source, dest) lock the file while copying? While one file is being
I have this function trying to print additional '.' every second while it's copying
i have a directory with around 1000 files....i want to run a same code
I need this while copying text from MS word to FCKeditor. The pop up
I'm copying and inserting rows in an Excel sheet, like so: while (rowsToAdd >
I am having problem in copying files to Xcode bundle. I have some files
I'm looking for a way to update my progress bar while copying a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.