C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Windows »

How to over come the issue "Cannot create a file when that file already exists"


Posted Date: 05 Nov 2009      Posted By: Ramesh M      Member Level: Silver     Points: 1   Responses: 5



hi

this is Ramesh

i have winforms, i trying to copy the file one location to another,if same file name is there i need to overwrite, but i got error like "Cannot create a file when that file already exists."

but my query is i want to overwite what should i do?
but i'm trying File.copy and File.move method not in use same error come out....
i'm novice..in c#

advance wishes





Responses

Author: vipul    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi,
Please provide code here so can check that code and give solution for your query.

Please Rate This Answer If They Helpful

Thanks & Regards
Patel Vipul



Author: Anuraj    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

The Copy Method contains an Overwrite parameter.

Thanks
Anuraj
THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS.
BEWARE OF BUGS IN THE ABOVE CODE; I HAVE ONLY PROVED IT CORRECT, NOT TRIED IT.
dotnetthoghts



Author: Anil Kumar Pandey    05 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

hi,

simply use the Over write option for the same, or delete the file before it created..


if (File.Exists(strLogFile))
{
File.Delete(strLogFile);
}


Thanks & Regards
Anil Kumar Pandey



Author: Pannalal Sinha    05 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Microsoft.VisualBasic.FileIO.FileSystem.CopyFile(sourcefilename,destinationfilename,true); //true for overwrite

Thanks
Panna



Author: yugandherReddy    10 Nov 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

use the following line..

File.Copy(@"C:\Xcalibur\tmuninst.ini", @"C:\Xcalibur\data\tmuninst.ini",true);



Post Reply
You must Sign In to post a response.
Next : System.IO; Ecception?
Previous : Getting Remote Machine folder Information
Return to Discussion Forum
Post New Message
Category: Windows

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use