0

I write the code below to delete a file:

FileInfo file = new FileInfo(filename);
file.Delete(Path);

but I am getting the error that file.Delete(path) takes 1 argument please help me

1
  • 2
    Haha, 7 nearly identical answers in < 5 minutes. Commented Sep 11, 2009 at 4:34

5 Answers 5

6

The method Delete of FileInfo does not accept any parameter, so you need to write your code like this:

FileInfo file = new FileInfo(filename); 
file.Delete();
Sign up to request clarification or add additional context in comments.

Comments

3

You are creating an instance of FileInfo having a filename as an arguement. Method file.Delete() will remove the file which you passed through a constructor. In fact, the argument of constructor must be an absolute path along with filename.

String filename=@"c:\xyz\aa.txt";
FileInfo file=new FileInfo(filename);
file.Delete();

1 Comment

Same answer with difference of 8 seconds :)
3

Your use of FileInfo.Delete takes no arguments.

You want something like:

FileInfo file = new FileInfo(filename); 
file.Delete();

1 Comment

@Surya sasidhar: You know you can accept his answer if it resolve your problem. It is just the way StackOverflow works...
1

try this

   if (System.IO.File.Exists(path))
            {
                System.IO.FileInfo info = new System.IO.FileInfo(path);
                System.IO.File.SetAttributes(info.FullName,     
                                       System.IO.FileAttributes.Normal);
                System.IO.File.Delete(info.FullName);
            }

Comments

1

Your code should be as below :

FileInfo file = new FileInfo(filename);
file.Delete();

The Delete method of FileInfo object does not take any arguments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.