Search code examples
c#windows-store-appsstorelarge-data

Store data in Windows Store app


Short version: How would you store "large" data in a Windows Store app, using C#?

Long version: I have a json string that I could either store as string (around 65 KB) or - when serialized - as object. I originally thought that I could use something like this:

    public static void SaveData(string param, object value)
    {
        Windows.Storage.ApplicationDataContainer settings = Windows.Storage.ApplicationData.Current.LocalSettings;       
        Windows.Storage.ApplicationDataCompositeValue composite = new Windows.Storage.ApplicationDataCompositeValue();
        composite[param] = value;
        settings.Values[param] = composite;
    }

I tried that, but my app shows the following error:

WinRT information: Error trying to write setting in application data composite value

The error is not really helping me, it simply does not want to save my data. I have just read online that there is only a ridiculous small amount of Bytes allowed to store in the local settings in a Windows Store app using C#.

Is there a fast, safe and elegant way to store my string/object otherwise? Do I really need to write it into a file by myself? Using SQLLite would also be way too much for just this string.


Solution

  • The data you are trying to store in local settings container exceeds the limits. Quoting from here: ApplicationData.LocalSettings | localSettings property

    The name of each setting can be 255 characters in length at most. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size.

    You can use ApplicationData.LocalFolder | localFolder instead to store the data. There is sample code is in that link too.