Click here to Skip to main content
11,932,103 members (58,489 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I have a problem with deleting the file in C#
In my code

if (System.IO.File.Exists(destination))
In my code the problem is
destination file already exist when i create a new file it will copied into destination folder with the name as destination

problem occurred when file size is big..

problem is file delete is not completed and file copy is start......
Frown | :( ...

sorry for my english....

Any Help will sufficient....

Posted 12-Sep-12 21:58pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just use File.Move:
if (System.IO.File.Exists(destination))
_Amy 13-Sep-12 3:08am
ridoy 13-Sep-12 3:53am
manoj12.shrivastava 13-Sep-12 5:32am
sir i have tried this but it is not working for me....
i m getting error can not create file it is already exist....
OriginalGriff 13-Sep-12 5:35am
It's pretty obvious what the problem is.
Try changing "file" to "destination"
manoj12.shrivastava 13-Sep-12 5:48am
Thanks for you reply ....
But in my case it's not working ..
actually the problem is

I have to delete file first if exist in destination folder
after that copy/move new file with the same name in destination folder..

My problem is that the file being deleted is a large video file typically 60 to 80MB, so this takes time to delete. In the mean time the following file copying code executes and tries to replace the file. Is there a way for me to hold the file copy operation and until the deletion is completed?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100