[英]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.