简体   繁体   English

如何在Windows 8中存储漫游文件?

[英]How to store roaming files in Windows 8?

I'm trying to store a file and roam it to other devices in Windows 8. The official documentation on this states: 我正在尝试存储文件并将其漫游到Windows 8中的其他设备。有关此文档官方文档说明:

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. 在其app数据存储中,每个应用程序都有系统定义的根目录:一个用于本地文件,一个用于漫游文件,一个用于临时文件。

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 使用以下定义的函数: 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... MSDN: http://msdn.microsoft.com/en-us/lib ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何存储BitmapImage Localy或Roaming? - How to store a BitmapImage Localy or Roaming? Windows Phone 8.1如何永久删除漫游设置? - Windows Phone 8.1 How to permanently remove Roaming Settings? 如何在 Windows 10 和 XBOX One UWP 应用程序之间使用漫游设置 - How to use roaming settings between Windows 10 and XBOX One UWP app windows 8 app漫游存储与自定义类 - windows 8 app roaming storage with custom class 在Windows 2008上以编程方式创建漫游用户配置文件 - Creating roaming user profiles programmatically on Windows 2008 在C#中的Windows漫游文件夹中写入值 - Strore values in windows Roaming folder in C# 如何在Windows Store应用启动时自动加载以前使用的文件 - How to automatically load previously used files on Windows Store app startup 构建后/构建前将文件复制到AppData \\ Roaming - Copying Files into AppData\Roaming after/before building 如何使用Windows Store应用程序编程从Windows 8中的特定文件夹中获取文件? - how to get files from particular folder in windows 8 using windows store app programming? 如何在漫游中保存字典变量-C# - How to save a Dictionary variable in roaming - C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM