I'm trying to store a file and roam it to other devices in Windows 8. The official documentation on this states:

Within its app data store, each app has system-defined root directories: one for local files, one for roaming files, and one for temporary files.

And further down, it states:

App files can be local or roaming. The files that your app adds to the local data store are present only on the local device. The system automatically synchronizes files your app adds to the roaming data store on all devices on which the user has installed the app.

However, it does not go on to state how files (not normal data) can be roamed.

Where do I go to find more about roaming files, and not just normal data?

有帮助吗?

解决方案

Use the functions defined in: Windows.Storage.ApplicationData.Current.RoamingFolder

For example:

public async void RoamData()
{
    var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder;
    var needToCreate = false;

    try
    {
        var sampleFile = await roamingFolder.GetFileAsync("dataFile.txt");
        string fooBar = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);
    }
    catch (Exception)
    {
        // fooBar not found
        needToCreate = true; // set a boolean to create the file. Cant be done here cause you cant await in a catch clause.
    }

    if (needToCreate)
    {
        var sampleFile = await roamingFolder.CreateFileAsync("dataFile.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);
        await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "fooBar content of the file.");
    }
}

MSDN: http://msdn.microsoft.com/en-us/lib...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top