我有一个Windows Mobile 6.5应用程序没有任何限制。我生成文件并将其放在底座上,连接到PC,并可以从Windows资源管理器中复制。
我需要能够在Windows Phone 8.1中执行相同操作,生成应该可以在任何文件夹上访问的文本或csv文件,最好是Documents文件夹,可以通过Windows资源管理器复制到pc。
我一直在尝试不同的方法,但它们都不起作用。
文件夹选择器:(抛出不支持的错误)
Windows.Storage.Pickers.FolderPicker picker = new Windows.Storage.Pickers.FolderPicker();
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads;
StorageFolder folder = await picker.PickSingleFolderAsync();
外部存储:(访问被拒绝错误)
StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
StorageFolder sdCard = (await externalDevices.GetFoldersAsync()).FirstOrDefault();
文件:(访问被拒绝错误)
StorageFolder folder = KnownFolders.DocumentsLibrary;
答案 0 :(得分:0)
我让它工作,至少在MusicLibrary文件夹上。
首先,转到项目属性 - >申请 - >包装清单 - > 能力(标签) - >查看音乐库
public static async Task<bool> WriteFile(string data)
{
StorageFolder mfolder = KnownFolders.MusicLibrary;
StorageFolder folder = await mfolder.CreateFolderAsync("MyFolder", CreationCollisionOption.OpenIfExists);
StorageFile file = await folder.CreateFileAsync("log.txt", CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteTextAsync(file, data);
return true;
}