Sascha
Sascha

Reputation: 10347

Deployment of LocalState folder

I'm using the LocalState folder to enable caching for my Windows 8 application. To provide sample data (the application uses a webservice to gather it's data), I would like to provide a default bunch of data already cached.

Can I provide sample data for LocalState that will be in the application package?

Upvotes: 0

Views: 1370

Answers (2)

Jeff Brand
Jeff Brand

Reputation: 5633

Here is some sample JS code - should be able to convert to .NET fairly easily - use async/await in place of the Promises.

WinJS.Application.local.exists('somedata.json').done(
               function (found) {
                   if (!found) {
                       return copyStartData('somedata.json');
                   }
               }
           );

function copyStartData(copyfile) {
        return Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync('startdata').then(
            function (startData) {
                return startData.getFileAsync(copyfile).then(
                    function (file) {
                        if (file) {
                            return file.copyAsync(WinJS.Application.local.folder);
                        }
                    });
            });
    }

The function takes the name of a file you want to copy from your install package to the users local machine.

Upvotes: 2

Jim O'Neil
Jim O'Neil

Reputation: 23774

You could put the file(s) into your package and then on startup check to see if there is already data in the Local Folder, if not, copy/populate it from the package storage (see CopyAsync, for instance). If so, do nothing.

Upvotes: 3

Related Questions