0

In xamarin.forms(visual studio) file existing checking time app went to crash like below picture:enter image description here

In Portable Project :

public interface ISaveAndLoad
{
    void SaveData(string fileName, string data);

    string LoadData(string fileName);

    bool FileExists(string fileName);
}

In Android Project :

  public class FileDiskOperationsAndroid : ISaveAndLoad
{
    public void SaveData(string fileName, string data)
    {
        var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        var filePath = Path.Combine(documentsPath, fileName);
        File.Delete(filePath);
        System.IO.File.WriteAllText(filePath, data);
    }
public bool FileExists(string fileName)
    {
        var documnetsPath = 
        Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        var filePath = Path.Combine(documnetsPath, fileName);
        return File.Exists(filePath);
    }
}
jesto paul
  • 438
  • 11
  • 21
  • 2
    Have you put dependency for your `FileDiskOperationsAndroid `? – Lee Nov 20 '17 at 07:18
  • i am implement ISaveAndLoad interface in android and ios project class like:FileDiskOperationsAndroid , FileDiskOperationsIos – jesto paul Nov 20 '17 at 07:23
  • I know, i think the thing null is probably your `DependencyService.Get`. You can split the declaration and the method `fileExist` to check which is the one cause that. – Lee Nov 20 '17 at 07:37
  • Thanks @Lee for your reply – jesto paul Nov 20 '17 at 10:22
  • 1
    just to remind you that you need to add dependecy in your `FileDiskOperationsAndroid` before you use `DependencyService.Get` – Lee Nov 21 '17 at 00:28

0 Answers0