iOS Path in Xamarin.Form to save data

119 Views Asked by At

I want to save the data on a csv file and I receive the Error that the Path doesn't exist. does anyone knows the correct Path ? I've searched in Internet and used the different paths but still doesn't work.

1

There are 1 best solutions below

0
On

For getting the path to save files on iOS i used something like

            string photosPath = Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments ) + "/Photos";
            IFileSystem fileSystem = FileSystem.Current;
            IFolder rootFolder = fileSystem.LocalStorage;
            IFolder photosFolder = rootFolder.CreateFolderAsync( photosPath, CreationCollisionOption.ReplaceExisting ).Result;
            ImageRepository.ImagePath = photosPath;

Add this in iOS project.

Saved the path in another class instance to easily access it anywhere.

public class ImageRepository
    {
        public static string ImagePath { get; set; }
    }

Use ImageRepository.ImagePath as a path everywhere, where you want to save your file.