Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

File.Delete not deleting file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Salman Zari Ghanvi - 03 Dec 2004 16:19 GMT
When the following code is execute and the file already exists, the file is
not actually deleted (in file properties - created date does not change) -
but only the modified and accessed date changes.

No exception is raised.

How can I ensure that file is actually deleted? I want to raise create event
for another application which is monitoring this folder similar to file
system watcher.

Thanks.

if (!File.Exists(fileName))
{
File.Delete(fileName);
}

using (StreamWriter sw = new StreamWriter(fileName,false))
{
 sw.Write(content);
 sw.Flush();
}
Marina - 03 Dec 2004 17:50 GMT
Your code says to delete the file if it does *not* exist.  Which really
makes no sense, since if it doesn't exist, there is nothing to delete.
Sounds like you never actually stepped into this code.  Take the '!' out of
the if statement.

> When the following code is execute and the file already exists, the file is
> not actually deleted (in file properties - created date does not change) -
[quoted text clipped - 18 lines]
>   sw.Flush();
>  }
Salman Zari Ghanvi - 03 Dec 2004 20:43 GMT
You are right ...!!!!!

Looks like i need to take a break :)

Thanks.

> Your code says to delete the file if it does *not* exist.  Which really
> makes no sense, since if it doesn't exist, there is nothing to delete.
[quoted text clipped - 27 lines]
>>   sw.Flush();
>>  }
Salman Zari Ghanvi - 03 Dec 2004 20:51 GMT
Actually, I found that my actual code didnt had that (!)...

I ran this through debug mode (step by step) and saw the file getting
disappear. But on the creation step, I see the same behaviour: the file is
created with the old date - while the accessed and modified are current.

Can anyone try to reproduce it? (after correct my original posted code).

Thanks.

> Your code says to delete the file if it does *not* exist.  Which really
> makes no sense, since if it doesn't exist, there is nothing to delete.
[quoted text clipped - 27 lines]
>>   sw.Flush();
>>  }
Salman Zari Ghanvi - 06 Dec 2004 19:42 GMT
Found the solution:
Its an OS 'feature' called tunneling. mskb:12190 (file system tunneling
capabilities).

Problem was fixed after making the thread sleep for 15 seconds (default
value - can be changed thru registry) b/w delete and recreate.

> When the following code is execute and the file already exists, the file
> is not actually deleted (in file properties - created date does not
[quoted text clipped - 18 lines]
>  sw.Flush();
> }
mumtaz khan - 22 Dec 2004 20:02 GMT
Hi Salman

I have got some clue on deleting a file that does not exist. Unfortunately, I think its only possible using Java, not sure about .NET

If you wanna know, then in that case I will need to meet you in person as I can demonstrate this only on my laptop (not on any other machine)

I am coming to MDW, IL on Jan 9 - 10th. Let me know if we can meet.

c u .. reply me at
makcalif **at** yahhh0000 dot com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.