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

  • SEARCH
  • Home
  • 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 8124011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:20:24+00:00 2026-06-06T06:20:24+00:00

I want to find a way to copy one file to multiple locations simultaneously

  • 0

I want to find a way to copy one file to multiple locations simultaneously (with C#).

means that i don’t want the original file to be read only one time, and to “paste” the file to another locations (on local network).

as far as my tests showed me, the

File.Copy() 

will always read the source again.

and as far as i understand, even while using memory, that memory piece gets locked.

so basically, i want to mimic the “copy-paste” to the form of one “copy”, and multiple “paste”, without re-reading from the Hard Drive again.

Why ?
because eventually, i need to copy one folder (more than 1GB) to many computers, and the bottleneck is the part the i need to read the source file.

So,
Is it even possible to achieve ?

  • 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-06T06:20:26+00:00Added an answer on June 6, 2026 at 6:20 am

    Rather than using the File.Copy utility method, you could open the source file as a FileStream, then open as many FileStreams to however many destination files you need, read from the source, and write to each destination stream.

    UPDATE Changed it to write files using Parallel.ForEach to improve throughput.

    public static class FileUtil
    {
        public static void CopyMultiple(string sourceFilePath, params string[] destinationPaths)
        {
            if (string.IsNullOrEmpty(sourceFilePath)) throw new ArgumentException("A source file must be specified.", "sourceFilePath");
    
            if (destinationPaths == null || destinationPaths.Length == 0) throw new ArgumentException("At least one destination file must be specified.", "destinationPaths");
    
            Parallel.ForEach(destinationPaths, new ParallelOptions(),
                             destinationPath =>
                                 {
                                     using (var source = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                                     using (var destination = new FileStream(destinationPath, FileMode.Create))
                                     {
                                         var buffer = new byte[1024];
                                         int read;
    
                                         while ((read = source.Read(buffer, 0, buffer.Length)) > 0)
                                         {
                                             destination.Write(buffer, 0, read);
                                         }
                                     }
    
                                 });
        }
    }
    

    Usage:

    FileUtil.CopyMultiple(@"C:\sourceFile1.txt", @"C:\destination1\sourcefile1.txt", @"C:\destination2\sourcefile1.txt");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find a way to copy data from one table in
I want to find a way to execute increment for every 5 mins, please
I want to find a way to get all the sub-elements of an element
I WANT to find out if a there is a way to check if
i want to update my sqlite database but i cannot find the way to
Could anyone find a way of improving this code a bit? I want to
I want to have a good test setup but, I can't find a way
I've been searching, but can't find a way to do this. I want the
What is the easyest way to find which tab is on. I want to
This will probably be obvious but I can't find the best way. I want

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.