Hi,
I'm trying to delete a file and the following
File.Delete(
"C:\\mytext.txt");causes an error saying "The name 'file' does not exist in the current context"
How can I fix this error
Thanks,
Bruce
Hi,
I'm trying to delete a file and the following
File.Delete(
"C:\\mytext.txt");causes an error saying "The name 'file' does not exist in the current context"
How can I fix this error
Thanks,
Bruce
Deleting a file
ivanbydg
That's an error at compile time.
You've got to specify the full name of File type.
So, with
System.IO.File.Delete("c:\\mytext.txt");
should work fine.
Hans Bothe
Is this a compilation error or a runtime error
If it literally says 'file' and this is a compilation error then you have not properly capitalized the name of the class. You have entered
file.Delete("c:\\mytext.txt");
Change it to
File.Delete("c:\\mytext.txt");
C# is case sensitive.
If this is a runtime error then something else must be going on. If the file doesn't exist then the method will not throw an exception.
Michael Taylor - 1/1/06
fungicide
if (File.Exists("C:\\mytext.txt"))
File.Delete("C:\\mytext.txt");
Thanks
Wayne
tickling
Please add using System.IO;
Happy new year,
XZ