Click here to Skip to main content
Rate this: bad
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 at 13-Sep-12 3:08am
ridoy at 13-Sep-12 3:53am
manoj12.shrivastava at 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 at 13-Sep-12 5:35am
It's pretty obvious what the problem is.
Try changing "file" to "destination"
manoj12.shrivastava at 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
0 Peter Leow 255
1 Mika Wendelius 240
2 CHill60 195
3 TheRealSteveJudge 180
4 Zoltán Zörgő 178
0 Sergey Alexandrovich Kryukov 8,658
1 OriginalGriff 6,591
2 Peter Leow 3,982
3 Zoltán Zörgő 3,604
4 Richard MacCutchan 2,510

Advertise | Privacy | Mobile
Web03 | 2.8.150123.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