PCL Storage

Hello,
I begin in Xamarin and I would like use PCL Storage ,
I download the Nugget Package and I use it for all my project (only Android and IOS I deleted the UWP platform)
I Create a class ( .cs ) where I included all functions of data storage like this :
https://theconfuzedsourcecode.wordpress.com/2015/05/19/easily-implement-data-storage-service-in-xamarin-forms-using-pcl-storage/
And now I want that my datas of my Page SettingsPages.Xaml ( One Entry called IpAdress and One Entry called Port And One Button called Save )
is saved.
in the SettingPages.Xaml.cs i write this but but I'm getting lost :

    public async Task Settings_Click(object sender, EventArgs e)
    {

        var rootFolder = FileSystem.Current.LocalStorage;
        var file = await rootFolder.CreateFileAsync("memo.txt", CreationCollisionOption.ReplaceExisting);
        using (var stream = await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
        using (var writer = new StreamWriter(stream, System.Text.Encoding.GetEncoding("UTF-16")))
        {
            await writer.WriteLineAsync(AdresseIPEntry.Text);
            await writer.WriteLineAsync(PortEntry.Text);
        }
    }
    public async Task LoadAsync()
    {
        var rootFolder = FileSystem.Current.LocalStorage;
        var file = await rootFolder.CreateFileAsync("memo.txt", CreationCollisionOption.OpenIfExists);
        using (var stream = await file.OpenAsync(PCLStorage.FileAccess.Read))
        using (var reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("UTF-16")))
        {
            while (reader.Peek() > 0)
            {
                var stre = await reader.ReadLineAsync();
            }
        }
        var str = await file.ReadAllTextAsync();
        str = AdresseIPEntry.Text;
    }

I already Looked all sample on github and all google but I still can not
if you could help me it would be nice :) :)

PS : Sorry for my English mistakes

Sign In or Register to comment.