473,395 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Simple Copy Application

I am writing a small window app. All it does is depending on which button the user clicks it copies a file from one dir to another. Both the files are on network shares. . I am getting

IO Exception was unhandled
the file already exists

I just want to copy the files no matter if they already exist or not. Below is my code. What can I add to make it just copy no matter what?

Expand|Select|Wrap|Line Numbers
  1.            private void button2_Click(object sender, EventArgs e)
  2.         {
  3.             string fileToCopy = "S:/coversheets/worker.htm";
  4.             string newLocation = "F:/rbcover.htm";
  5.             System.IO.File.Copy(fileToCopy, newLocation);
  6.         }
Dec 12 '08 #1
3 1513
Curtis Rutland
3,256 Expert 2GB
First of all, please use [CODE] [/CODE] tags when you post your code. It makes it easier for us to read.

MOD.

Now on to your question:
File.Copy Method
Check out the second overload that takes a source, destination, and a bool value. Passing true will overwrite files of the same name.

In case you did not already know, the MSDN can help you with things like this. You can explore every object, and each object's properties/members/methods, and each method's overloads.

Also, if you are using Visual Studio, the IntelliSense popup can give you much of this information. Notice that when you start typing a method's parameters, the little popup window appears. It can show you what overloads a method has and what parameters they take.
Dec 12 '08 #2
Thanks, and thanks for the info about MSDN. That is a big help.
Dec 12 '08 #3
Curtis Rutland
3,256 Expert 2GB
Yeah, a little googling goes a long way. Try searching for the object you have questions about first.

For example, I found the page I just linked to you by searching for System.IO.File.Copy in google. First result. Sometimes it'll take more effort.

Have fun!
Dec 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Rob | last post by:
Dear all I'm well into designing my first ever Access database which is currently about 13 megs (.mdb file) containing data on progress and attainment of approx 500 students. What I want to...
2
by: Simon Harvey | last post by:
Hi everyone, Apologies for the very silly question I am about to ask: When I deploy an application, do I need to copy over the source code for the aspx pages and their code behinds, as well as...
6
by: Allan Rojas | last post by:
Hi there, i'm having this problem and i hope someone can help me out. We have this WebApplication in ASP.NET; we work on it in our local webserver. When we're done, we must upload the application...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
4
by: bob lambert | last post by:
Help I am trying to deploy to another pc a vb.net std 2002 windows form application. I am confused. I created a project - windows form I built form, compiled and debugged. I created a...
4
by: Ant | last post by:
Hi, I'm a newbie to .NET so... After developing a simple, non distributed application (if that's still applicable these days), how do I move the appliation to another PC? Is it simply a matter of...
6
by: Jim M | last post by:
I've been distributing a fairly mature, very specific MS Access application to end users in small offices of colleges for several years now. This is a part-time venture and low volume operation-...
0
by: myself337 | last post by:
in VB you can do this: Imports System Imports System.IO Module Module1 Sub Main() Dim path As String = "c:\temp\filetocopy.txt" ' put the file you
10
by: Jason | last post by:
I want to create a simple program with Two buttons on the form. BUTTON 1 - BACKUP PREFS this will do the following: Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla...
6
kenobewan
by: kenobewan | last post by:
Congratulations! You are one of the few who realise that over 80% of errors are simple and easy to fix. It is important to realise this as it can save a lot of time. Time that could be wasted making...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.