Search code examples
c#fileprocesscopycopy-paste

How to copy a file to another folder while a process is using it


How do I copy any file that is being used to another process to a specified folder, without affecting / corrupting what that process is doing?

Context: I'm making a program that will copy a project folder each X minutes to 2 cloud servers and 1 hard-drive, while that project is still open.


Solution

  • As mentioned in the post below:

    The important part is the FileShare.ReadWrite when opening the FileStream

    .

    How to copy a file while it is being used by another process

    In short, make sure that you specify the correct access parameters while opening the file.