How to fix the copy file problem in C# - Digital Tool Factory blog

How to fix the copy file problem in C#

Cavalry moving forwardphoto © 1918 National Library of Scotland | more info (via: Wylio)The Problem: You need to copy a file from one location on the server to another and cannot remember how.

The Cause: It is too short and simple, and easily forgotten

The Solution: Just use the following code:

public static void CopyAndRenameFile(string OldPath, string OldFileName, string NewPath, string NewFileName)
        if (File.Exists(OldPath + OldFileName))
            File.Copy(OldPath + OldFileName, NewPath + NewFileName, true);

That’s it!


This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


Written By Steve French


One response to “How to fix the copy file problem in C#”

  1. The problem is how to fix not how to copy.
    So, if we copied a file and we created a HashMap for this file (using MD5 or CRC32)before and after copying, so that we can check after copying that the file has been fully copied without any corruption.
    let’s assume that we find a corruption Pakete in this copied file.
    the question is: except of re-copying the file, is there any thing we can do to only fix the corrupted Pakete using MD5 or CRC32 ??
    Thanks in Advanced,

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.