Forum Xamarin.Forms

How to delete file which is stored in internal storage

I have downloaded a file which stores in internal storage. But whenever I am trying to delete that file, it is not working. This is my delete code.
private void Delete_Clicked(object sender, EventArgs e)
{
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}

    }

I am getting the path value but System.IO.File.Exists(path) always returns false.
Any suggestion plz.................

Answers

  • Amit_Malhi01Amit_Malhi01 Member ✭✭

    The Exists method returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.

    One way of seeing what's happening is to just try to read the file (e.g. with File.OpenRead). I'd be surprised if that succeeds - but if it fails, the exception should give you more information.

Sign In or Register to comment.