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


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.