0

I have a file named "Classes.jsa" in my application. I need to delete this file through C# code. Manually i can delete this file. But not able to delete it through coding. I tried to delete in Admin mode. But showing the error like

Access to the path denied "F:\MyApp\Classes.jsa"

MyCode:

sting fileName=@"F:\MyApp\Classes.jsa";
if(file.exists(fileName))
{
   File.Delete(fileName);
}

Anyone can resolve this issue?

Thanks and Regards, Kathiresan S.

Kathir Subramaniam
  • 1,195
  • 1
  • 13
  • 27

2 Answers2

1

Modify code from Kathir Subramaniam. I check my machine and it works

    [Test]
    public void FileDelete()
    {
        string fileName = @"D:\FileDelete\Classes.jsa";
        FileInfo file = new FileInfo(fileName);

        if (file.Exists)
        {
            file.IsReadOnly = false;
            File.Delete(fileName);
        }
    }
jalil
  • 85
  • 10
0

I got the answer for this.

The below code working for me:

Code:

sting fileName=@"F:\MyApp\Classes.jsa";
FileInfo file=new FileInfo(fileName);

if(file.exists(fileName))
{
   file.IsReadOnly=false;
   File.Delete(fileName);
}
Kathir Subramaniam
  • 1,195
  • 1
  • 13
  • 27