我正在尝试开发一个基本的 Windows 8 应用商店应用程序,只需创建一个新文件并向其中写入一些示例数据。但是,当我运行我编写的功能时,应用程序会挂起并且没有响应。我尝试了两种不同的文件创建方法,它们都具有相同的效果:
使用漫游文件夹:
Windows.Storage.StorageFolder roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder;
StorageFile file = await roamingFolder.CreateFileAsync("test.txt",CreationCollisionOption.ReplaceExisting);
string[] data = { "New project", "000000000" , "" };
await FileIO.WriteTextAsync(file, data[0]);
return new Project(file.Path, "New project", "", Windows.UI.Color.FromArgb(255, 0, 0, 0));
使用文件选择器:
Windows.Storage.Pickers.FileSavePicker fsp = new Windows.Storage.Pickers.FileSavePicker();
fsp.FileTypeChoices.Clear();
fsp.FileTypeChoices.Add("Plain Text", new List<string>() { ".jwp" });
fsp.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
fsp.SuggestedFileName = "New Project";
StorageFile file = await fsp.PickSaveFileAsync();
if (file != null)
{
string[] data = { "New project", "000000000" , "" };
CachedFileManager.DeferUpdates(file);
await FileIO.WriteLinesAsync(file, data);
Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
{
return new Project(file.Path, "New project", "", Windows.UI.Color.FromArgb(255, 0, 0, 0));
}
else
{
return null;
}
}
else
{
return null;
}
每次,它似乎挂在的行是:
await FileIO.WriteTextAsync(file,data[0]);
或者:
await FileIO.WriteLinesAsync(file,data);
分别。
有人知道这里发生了什么吗?我在选择器中选择的驱动器上肯定有空间,我什至可以看到选择器方法肯定是在创建一个文件(尽管大小为 0 字节),但我真的无能为力。