Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 781
andreas Avatar asked Dec 18 '13 01:12

andreas


People also ask

Where do Windows Store apps store data?

Microsoft uses a hidden folder named WindowsApps to install these Metro/Modern apps. The folder is located within the Program Files folder in the system drive (C:\). Data for all of the Modern Apps are stored in the AppData folder under the user's profile.

What is the difference between Windows Store and Microsoft Store?

The Microsoft Store – formerly called the Windows Store -- is an online marketplace for consumers to buy and download a variety of items. The store enables users to purchase hardware such as PCs, Surface products and Xbox consoles, or download software and digital content, including apps, games, movies or TV shows.

Does Windows app store still exist?

Microsoft Store has nearly everything you could want for your Windows device, including the latest games, popular movies and TV shows, creativity software, apps,1 and more.


1 Answers

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.

like image 63
yasouser Avatar answered Sep 27 '22 16:09

yasouser