Solved

Copying a file

Posted on 2004-08-26
4
206 Views
Last Modified: 2010-04-15
What's the easiest way to copy a file (in C#) from one directory to another?  The only thing I'll need to do in addition is to overwrite the original file automatically (no message box), since I'll be copying the file every 10 seconds, for hours on end.

Thanks.
0
Comment
Question by:ba272
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11906874
use ...

System.IO.File.Copy() it will have no issue with rewriting the file http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiofileclasscopytopic.asp
0
 
LVL 3

Expert Comment

by:sohilm
ID: 11907432
if you are trying to archive something, that I would use System.IO.File.Move()

SohilM.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11914070

FileInfo fileInfo = new FileInfo(@"d:\testfile.txt");
fileInfo.CopyTo(@"d:\testfile1.txt", true);  
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11914124
Instead of using Static method, a more object oriented way for cSharp programmers ;)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now