简体   繁体   中英

iOS Path in Xamarin.Form to save data

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 Inte.net and used the different paths but still doesn't work.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM